PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
290 stars 47 forks source link

Writing to an existing excel file will cause a warning when opening it. #54

Closed Blanket58 closed 2 years ago

Blanket58 commented 2 years ago

Pylightxl Version: 1.56 Python Version: 3.7.9 Platform: win 10 x64

Summary of Bug/Feature: Writing to an existing excel file will cause the warning "We found a problem with some content in Excel. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes." when opening it.

Traceback: There is no error in python.

Suggestion for fix: Erase the warning popup.

Code for reproducing the problem:

import pylightxl

data = [('start', 'end'), ('1', '2'), ('321', '432')]
db = pylightxl.Database()
db.add_ws(ws='Sheet1')
for row, x in enumerate(data, start=1):
    for col, value in enumerate(x, start=1):
        db.ws(ws='Sheet1').update_index(row, col, value)
pylightxl.writexl(db, 'test.xlsx')  # All went well when opening the excel file.
pylightxl.writexl(db, 'test.xlsx')  # The warning happened.
PydPiper commented 2 years ago

Hi @Blanket58 thank you for considering using pylightxl. We were not able to replicate the issue from our end. The file opens in excel without warning. Can you send us the 'test.xlsx' that you machine wrote with this script to see how it is different. In the mean time please double check that you do in fact have pylightxl v1.56

Blanket58 commented 2 years ago

As you request, I rechecked my version of pylightxl, I'm 100% sure it is v1.56. Here is my broken excel file and I'm using Excel 2016. test.xlsx

PydPiper commented 2 years ago

Hi @Blanket58 thank you for submitting the sample file. I was able to locate the source of the issue. There appears to be a custom.xml file that is created by your system when you create a spreadsheet. The write to existing workbooks in pylightxl works on the bare minimum of a spreadsheet (cell values), therefore any customization is removed on writing to existing. We have not encountered this file before but the new version will have a fix for you.

felipekleindias commented 2 years ago

Hello @PydPiper , I've been facing the same issue when trying to generate an excel file. I´m using the pylightxl version1.58. I was wondering if you could help to figure out what is happening.~ Thank you Sheet1.xlsx .

PydPiper commented 2 years ago

@felipekleindias hey sure i can take a look and get back to you this week

PydPiper commented 2 years ago

@felipekleindias it appears the sheet name was an empty string. Did the original worksheet have a sheet name? or did you alter the sheet name to be empty then try to write to this existing workbook? Either way that was the cause the issue. If you set the sheetname the be something with rename_ws() it should fix the issue. I will add a to rename_ws() as well to not allow for an empty string name

felipekleindias commented 2 years ago

Hello @PydPiper, Thank you for your help. This was indeed my problem. I´m generating the excel file from a table in a sqlite database and after your comment I noticed that I had a problem in my code when assigning the sheet name. Congratulation for the great job you' re doing with this library. I´m using it to import excel files to a sql database, run some scripts in sql and then export to an excel file. I don't know if other users have the same usage, but it would be nice to had in the library an option to read and write to a database. Thank you again and happy new year.