Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TibbersGo opened this issue Jan 18, 2021 · 5 comments

Comments

@TibbersGo
Copy link

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
Copy link
Author

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 TibbersGo changed the title When I use openpyxl to read the file, it says "Workbook contains no default style"? When I use openpyxl to read the xlsx file generated by pyexcelerate, openpyxl prompts "Workbook contains no default style"? Jan 18, 2021
@kevmo314
Copy link
Collaborator

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

@TibbersGo
Copy link
Author

TibbersGo commented Jan 19, 2021

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
Copy link

0x4e3 commented Jan 28, 2021

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

@kevmo314
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants