I want to create a program that uses openpyxl to transfer data from the original Excel file to the new Excel file.
Only 100 rows per Excel file should be included in the new Excel file, but the original Excel file has hundreds of rows.
In this case many workbook to make the workbook, don't know how to create a variable in a row.
for wbc in range(total_row_count//100):
wb = Workbook()
ws = wb.create_sheet("Sheet1", 0)
If the total number of rows (total_row_count) of the original file is 420, the for statement turns 4 times.
Then, I want to create WB 4 times. But I don't know how.
I thought it would be okay to combine them into strings, but it doesn't work.
If you know, please answer.
python openpyxl
Is this okay?
>>> from openpyxl import Workbook
>>> total_row_count = 420
>>> wb = [Workbook() for _ in range(int(total_row_count / 100))]
>>> wb
[<openpyxl.workbook.workbook.Workbook object at 0x0AC52390>,
<openpyxl.workbook.workbook.Workbook object at 0x0AC528F0>,
<openpyxl.workbook.workbook.Workbook object at 0x0AC57050>,
<openpyxl.workbook.workbook.Workbook object at 0x0AC57730>]
>>> wb[0]
<openpyxl.workbook.workbook.Workbook object at 0x0AC52390>
>>> wb[0].create_chartsheet("Sheet1", 0)
<Chartsheet "Sheet1">
© 2024 OneMinuteCode. All rights reserved.