PydPiper / pylightxl

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

Unable to save an excel file after modifing it. #23

Closed laksh225 closed 4 years ago

laksh225 commented 4 years ago

I tried modifying a file using the following script, but got an error as described below. I am using python 2.7.13 with windows 7. The excel sheet I imported is sales.xlsx

`import pylightxl as xl from datetime import datetime

def transform(): db = xl.readxl("sales.xlsx") sheet = db.ws("Sheet 1") k = 2 while str(sheet.index(k, 2)).startswith("VOLKPH"): inv_no_l = list(sheet.index(k, 2)) inv_no_l[5] = '0' sheet.update_index(k, 2,val = ''.join(inv_no_l)) sheet.update_index(k, 1, int(datetime.strftime(datetime.strptime(sheet.index(k, 1), format("%d-%m-%Y")), format('%Y%m%d'))))
k+=1 xl.writexl(db, "salesmodified.xlsx")

if __name_==\'__main_\\': transform() `

===== RESTART: G:\Automation\Python2_7\tally_xml_generator\transform.py =====

Traceback (most recent call last): File "G:\Automation\Python2_7\tally_xml_generator\transform.py", line 18, in transform() File "G:\Automation\Python2_7\tally_xml_generator\transform.py", line 15, in transform xl.writexl(db, "salesmodified.xlsx") File "G:\Automation\Python2_7\lib\site-packages\pylightxl\pylightxl.py", line 432, in writexl writexl_alt_writer(db, fn) File "G:\Automation\Python2_7\lib\site-packages\pylightxl\pylightxl.py", line 456, in writexl_alt_writer text = writexl_alt_app_text(db, temp_folder + '/docProps/app.xml') File "G:\Automation\Python2_7\lib\site-packages\pylightxl\pylightxl.py", line 586, in writexl_alt_app_text tag_vt_vector = root.find('./default:HeadingPairs//vt:vector', ns) File "G:\Automation\Python2_7\lib\xml\etree\ElementPath.py", line 286, in find return iterfind(elem, path, namespaces).next() File "G:\Automation\Python2_7\lib\xml\etree\ElementPath.py", line 264, in iterfind selector.append(ops[token[0]](next, token)) File "G:\Automation\Python2_7\lib\xml\etree\ElementPath.py", line 120, in prepare_descendant token = next() File "G:\Automation\Python2_7\lib\xml\etree\ElementPath.py", line 84, in xpath_tokenizer raise SyntaxError("prefix %r not found in prefix map" % prefix) SyntaxError: prefix 'vt' not found in prefix map

laksh225 commented 4 years ago

The fix I've tried is add namespaces.update(vt = 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes') to line 74 of ElementPath.py in the directory Lib\xml\etree. But this generates a different error.

===== RESTART: G:\Automation\Python2_7\tally_xml_generator\transform.py =====

Traceback (most recent call last): File "G:\Automation\Python2_7\tally_xml_generator\transform.py", line 17, in transform() File "G:\Automation\Python2_7\tally_xml_generator\transform.py", line 14, in transform xl.writexl(db, "salesmodified.xlsx") File "G:\Automation\Python2_7\lib\site-packages\pylightxl\pylightxl.py", line 432, in writexl writexl_alt_writer(db, fn) File "G:\Automation\Python2_7\lib\site-packages\pylightxl\pylightxl.py", line 456, in writexl_alt_writer text = writexl_alt_app_text(db, temp_folder + '/docProps/app.xml') File "G:\Automation\Python2_7\lib\site-packages\pylightxl\pylightxl.py", line 587, in writexl_alt_app_text tag_vt_vector.clear() AttributeError: 'NoneType' object has no attribute 'clear'

PydPiper commented 4 years ago

Hi @laksh225 thank you for considering pylightxl and submitting this issue. We are taking a look at it now

PydPiper commented 4 years ago

Initial assessment came back negative on the latest version of pylightxl on python 2.7.18. Going to download 2.7.13 and test there

PydPiper commented 4 years ago

created a docker container for python 2.7.13 downloaded the sales.xlsx and pip installed the latest pylightxl. i was not able to recreate the bug you are seeing. Are you using the latest version of pylightxl?

laksh225 commented 4 years ago

Yes, I am using the latest version V1.47. I think I figured out the problem. The problem was that I used openpyxl on the previous run to generate the salesmodified output file and now, when I changed to pylightxl, there was some problem in rewriting that file and maybe that caused this issue. Thanks for the quick reply!!!