The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Python
 Delete columns of a worksheet

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Joyserver 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.
9   L A T E S T    R E P L I E S    (Newest First)
minimax 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'>
ankur41 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()


minimax 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 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
Joyserver 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.
minimax 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 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


Chris D 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
Chris D 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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000