PyExcelerate icon indicating copy to clipboard operation
PyExcelerate copied to clipboard

When I use openpyxl to read the xlsx file generated by pyexcelerate, openpyxl prompts "Workbook contains no default style"?

Open TibbersGo opened this issue 5 years ago • 5 comments

I save the same file as another file with excel, and then it can be read with openpyxl, so I suspect that there is a problem with the pyexcelerate export file. How can I solve it?

TibbersGo avatar Jan 18 '21 08:01 TibbersGo

How can I fit python to read the xlsx file generated by pyecelerate? I tested several reading xlsx-related libraries, but they could not be read normally.

TibbersGo avatar Jan 18 '21 08:01 TibbersGo

Do you have some code to reproduce this issue? This is a bit curious.

kevmo314 avatar Jan 18 '21 15:01 kevmo314

This is the demo I used

from pyexcelerate import Workbook
workbook = Workbook()
data=[]
for j in range(100):
    data_list = ['a', 'b', 'c', 'd', 'e']
    data.append(data_list)
workbook.new_sheet("sheet1", data=data)
workbook.save("demo.xlsx")


from openpyxl import load_workbook
wb_data = load_workbook('demo.xlsx', read_only=True)
sheet = wb_data["sheet1"]
print(sheet.max_row)
print(sheet.cell(row=2, column=2).value)

When I use openpyxl to read the file, I cannot get the maximum number of rows of the file. Openpyxl will return "None".Although the maximum number of rows cannot be obtained, the value of the cell can be obtained.

TibbersGo avatar Jan 19 '21 01:01 TibbersGo

@TibbersGo to fix dimensions you should call sheet.calculate_dimension() according to openpyxl documentation

0x4e3 avatar Jan 28 '21 10:01 0x4e3

@TibbersGo thanks for the example, I missed the notification email so apologies for the delay. It does seem that PyExcelerate isn't setting some metadata correctly here so we should get this fixed. That being said I'm a bit tight on bandwidth. If you're interested in contributing we'd welcome a contribution here.

From the openpyxl source it seems that just a specific element needs to be set in the xml: https://github.com/chronossc/openpyxl/blob/master/openpyxl/reader/worksheet.py#L56

kevmo314 avatar Jan 28 '21 17:01 kevmo314