Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openpyxl access Excel worksheet by its index

I've googled and searched this question for a while with no success. Is it possible to open a worksheet in an Excel workbook with openpyxl by using its index? For example, I want to insert a photo into the second worksheet for every workbook in my folder. If the sheet name is variable, could I open the sheet using its index? Any help would be greatly appreciated, thanks!

like image 401
Vivian Avatar asked Oct 19 '25 03:10

Vivian


1 Answers

Actually, using index to open a sheet is easy. Check the python code example given below:

from openpyxl import load_workbook
workbook = load_workbook("your path")
sheet = workbook.worksheets[1]
like image 153
axlis Avatar answered Oct 20 '25 18:10

axlis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!