kz26 / PyExcelerate

Accelerated Excel XLSX Writing Library for Python 2/3
https://pypi.org/project/PyExcelerate/
BSD 2-Clause "Simplified" License
530 stars 60 forks source link

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

Open TibbersGo opened 3 years ago

TibbersGo commented 3 years ago

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 commented 3 years ago

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.

kevmo314 commented 3 years ago

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

TibbersGo commented 3 years ago

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.

0x4e3 commented 3 years ago

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

kevmo314 commented 3 years ago

@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