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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 How to fix the workbook name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

fly1342

Korea
7 Posts

Posted - 09/18/2022 :  8:09:21 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
If I Make a worksheet, the workbook name become something like this.
'Book3 - minuschart'

When I make a new worksheet like below.
wks_minus = op.new_sheet('w', 'minuschart')

But later when I want to refer to the book.
I have to refer to the workbook as below..

wb = op.find_book('w', 'Book3')

Is there any way to fix the workbook name as I want when making the worksheet?
Or Do I have to make a workbook and then make a worksheet linked to it?

Since the naming of the book keeps changing everytime I make a worksheet, I'm having a hard time referring to the workbook I want.

Please help ^^ㅠㅠ

john

minimax

351 Posts

Posted - 09/19/2022 :  05:44:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please try using add_sheet()

wb=op.find_book('w','Book3')
wks=wb.add_sheet()
Go to Top of Page

fly1342

Korea
7 Posts

Posted - 09/19/2022 :  7:42:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The question was how to change the book name.
When I make a new sheet the book name keeps changing
Book1 Book2 Book3 .. etc.

What I want to do is after making a new worksheet by loading excel.
I want to refer to the following worksheet(workbook) and add some calculations to make a new worksheet.

I can make a new worksheet by adding a sheet with the above method that you mentioned..

But I have to refer to the Worksheet that I loaded excel with.
But when I load excel with the below method.

op.new_sheet()

The Book name is made randomly.
So I want to know how I could fix the book name to a specific name.

So I can refer to the book with the following method below.
wb = op.find_book('w', 'Book_name')

Since if I don't fix the Book name, it keeps changing everytime I make a new worksheet.



john
Go to Top of Page

minimax

351 Posts

Posted - 09/19/2022 :  9:47:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Sorry that we are not very sure what you need.

1. You can specify the book name on new sheet moment, like
wks=op.new_sheet('w', 'hello')

but note that it will try enumeration if there already exists a book named as "hello".


2. the book name does not affect the subsequent load excel action, as long as you have the worksheet object. like
wks=op.new_sheet('w')
f = op.path('e')+r'Samples\Graphing\Excel Data.xls'
wks.from_file(f)


3. If you do need the book name, you can try
wks=op.new_sheet('w')
wb=wks.get_book()
print(wb.name)
wb.name='hello'  #rename short name
wb.lname='world'  #rename long name



Go to Top of Page

fly1342

Korea
7 Posts

Posted - 09/20/2022 :  01:36:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your support.

I was keep trying ..
op.new_sheet('w', 'plus_chart')

But it didn't work.
But when I tried below it worked.

op.new_sheet('w', 'plusBook')

Seems that if underbar is in the naming, it doesn't get applied as the Book name.

I should have tried it... Sorry and Thanks for your support!

john
Go to Top of Page

minimax

351 Posts

Posted - 09/20/2022 :  03:33:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Good to know it is solved now.

There is some further comments:

The 2nd argument in new_sheet() is a kind of dynamic.

When it is a valid short name, it will be set as the short name of the book,
when it is not, it will be set as the long name of the book.

And underbar is not a valid character for short name in Origin.

See more in
https://www.originlab.com/doc/en/Origin-Help/ChildWindow-Names
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000