Author |
Topic |
|
Joyserver
Austria
5 Posts |
Posted - 06/25/2021 : 09:35:55 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): Origin pro 2021 (64 bits) Operating System: Windows 10
Hi,
I cannot find in the Originpro package a function to delete columns of a worksheet. The closest thing I got is wks.clear() but this only clear the data and does not remove existent columns.
Besides, I cannot find any function to remove worksheets either. Are those functions (delete columns, delete worksheet) available in Originpro package at all?
Thanks. |
|
Chris D
428 Posts |
Posted - 06/25/2021 : 12:11:00 PM
|
Do you want to delete specific columns or ones off the end of the worksheet? Likewise with worksheets.
Thanks, Chris Drozdowski Originlab Technical Support
|
|
|
Chris D
428 Posts |
Posted - 06/25/2021 : 12:21:13 PM
|
You have to use some LabTalk from within Python until we implement the functionality in the originpro package.
Try:
import originpro as op
# Assumes book has more than one sheet
wb = op.find_book()
# Reduce number of columns
wks1 = wb[0]
wks1.lt_exec('wks.ncols=2')
# Delete specified zero-based column number
col_num = 0
wks1.lt_exec(f'range bb={col_num + 1}; del bb;')
# Delete specified sheet
wks2 = wb[1]
wks2.lt_exec('layer -d')
Thanks, Chris Drozdowski Originlab Technical Support
|
|
|
Joyserver
Austria
5 Posts |
Posted - 06/28/2021 : 04:07:10 AM
|
Hi, Chris
Thanks for your support. It is good to know that we can embed labtalk in python. I tried your code. It worked but with some modification: note that the object worksheet does not have lt_exec function. Instead, we have to use lt_exec with the object workbook. Here I have a further question: can we refer to a worksheet by its name? For instance, can wks=wb[0] be replaced by something like wks=wb['ABC'] (which does not work)?
quote: Originally posted by Chris D
You have to use some LabTalk from within Python until we implement the functionality in the originpro package.
Try:
import originpro as op
# Assumes book has more than one sheet
wb = op.find_book()
# Reduce number of columns
wks1 = wb[0]
wks1.lt_exec('wks.ncols=2')
# Delete specified zero-based column number
col_num = 0
wks1.lt_exec(f'range bb={col_num + 1}; del bb;')
# Delete specified sheet
wks2 = wb[1]
wks2.lt_exec('layer -d')
Thanks, Chris Drozdowski Originlab Technical Support
|
|
|
minimax
351 Posts |
Posted - 06/28/2021 : 10:06:56 PM
|
Hi Joyserver,
As to
quote: For instance, can wks=wb[0] be replaced by something like wks=wb['ABC'] (which does not work)?
What error do you meet? We suppose it should work in Origin 2021 if 'ABC' is the name of the worksheet, like
import originpro as op
wb=op.find_book()
ws=wb['abc'] #sheet name is case insensitive
print(ws) --> [Book1]ABC is dumped.
|
|
|
Joyserver
Austria
5 Posts |
Posted - 06/29/2021 : 01:52:51 AM
|
Hi, minimax
I have checked it again. Possibly I made some mistake when quoting the name of a worksheet. It works now.
Thanks. |
|
|
ankur41
4 Posts |
Posted - 08/04/2022 : 11:06:21 PM
|
Hi all,
I am trying to delete the worksheets, the names of the worksheets are stored in "toDelete". below is the code.
for wb in toDelete: print(wb) ws=op.find_sheet('w',wb) print(ws) #ws.destroy()
however, nothing in passed the 'ws' hence i cant use ws.destroy. If is use lt.exec(layer -d) the software crashes. Any idea where i am going wrong?
Thanks Ankur |
|
|
minimax
351 Posts |
Posted - 08/05/2022 : 02:05:56 AM
|
Hi
Would you mind to try if following works?
for wb in toDelete:
ws=op.find_sheet('w',wb.name)
print(ws)
ws.destroy()
or
for wb in toDelete:
for wks in wb:
print(ws)
ws.destroy()
|
|
|
ankur41
4 Posts |
Posted - 08/08/2022 : 01:37:42 AM
|
Thanks minimax,
I tried both your suggestions, with a little modifcation. This worked:
for wb in toDelete:
print(wb)
wb.destroy()
Just out of curiosity - do you have any idea why the below line doesnt return any value for 'ws'
ws=op.find_sheet('w',wb.name) or
ws=op.find_sheet('w',wb) ..... where 'toDelete[]' has worksheet names
when it is used like this:
for wb in toDelete:
ws=op.find_sheet('w',wb.name)
print(ws)
ws.destroy()
regards Ankur
quote: Originally posted by minimax
Hi
Would you mind to try if following works?
for wb in toDelete:
ws=op.find_sheet('w',wb.name)
print(ws)
ws.destroy()
or
for wb in toDelete:
for wks in wb:
print(ws)
ws.destroy()
|
Edited by - ankur41 on 08/08/2022 01:44:09 AM |
|
|
minimax
351 Posts |
Posted - 08/08/2022 : 10:52:00 PM
|
1. First of all, you may need to double check the concept of workbook vs. worksheet, see image below.
2. you may check what type of toDelete is?
Is it the name(string type)? or Origin object(object type)? like
wb=op.find_book()
wbn=wb.name
print(type(wb))
print(type(wbn))
# output below
# <class 'originpro.worksheet.WBook'>
# <class 'str'>
|
|
|
|
Topic |
|