How to assign a variable name to a worksheet in openpyxl?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to assign a variable name to a worksheet in openpyxl?



In openpyxl 2.4.8, is it possible to give a created Excel worksheet a name that depends on user input, for example?



What I tried so far is the most obvious thing


from openpyxl import load_workbook
...
wb=load_workbook("Some_WB_name.xlsx")
ws=wb.create_sheet("Data_set_", int(some_user_input))



but it gives me a worksheet called just "Data_set_". I also checked the docs https://openpyxl.readthedocs.io/en/2.5/index.html but did not find anything related there.



Thanks in advance.




1 Answer
1



from this PDF documentation, the create_sheet method has two optional arguments:


create_sheet



create_sheet(title=None, index=None)


create_sheet(title=None, index=None)



This method will create a worksheet (at an optional index).



Parameters



Your user input is being passed as the second parameter (index). If you need that input as part of the sheet name, you need to append that to the title parameter:


index


title


ws = wb.create_sheet('Data_set_' + str(some_user_input))






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived