Python library to open existing .xlsx workbook with charts [closed]

与世无争的帅哥 提交于 2019-12-10 11:05:09

问题


I have to read a certain .xlsx file (file1.xlsx), pull data from another .csv files (file2.csv) and write the processed data into the original file (file1.xlsx) along with some charts. The file has existing charts, I have looked into openpyxl, xlswriter, xlsread, and other python libraries.

It seems openpyxl is the only library which allows you to read and write files back with the same library. Others like xlswriter only write, or xlsread only read.

However, even openpyxl is limited, in that if I read a file which already has charts, the charts are lost.

The only way I can think of doing this from python only, is using a combination of openpyxl and pywin32. 1. extract data from file2.csv, process data and printout to another .xlsx file (or hold in memory) 2. copy data from memory or from file3.xlsx and past into file1.xlsx using pywin32.

Before, I dive into pywin32, I wanted to check if this is a feasible strategy. I am working in a Linux environment, so would have preferred to stay in this environment while doing the data processing, but I dont know whether there is another way out.

Has anybody read an excel workbook with charts and written data out to the same excel workbook with openpyxl or other libraries (WITHOUT LOSING THE CHARTS)?


回答1:


Preservation of charts is a feature that is being introduced in openpyxl version 2.5 (see here and here). So you could try to install and use the 2.5 development version of openpyxl.




回答2:


Panda's maybe able to read and write to Excel. It uses xlrd to read excel files and xlswriter to write it out. So it seems that it can load the Excel file usign xlrd, into memory and pass it out to xlsxwriter, to save the file.

https://pandas.pydata.org/pandas-docs/stable/io.html#io-excel-writer



来源:https://stackoverflow.com/questions/46386143/python-library-to-open-existing-xlsx-workbook-with-charts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!