Many spreadsheets have formulas and formatting that Python tools for reading and writing Excel files cannot faithfully reproduce. That means that any file I want to create p
I'm 90% confident the answer to "can pandas
do this" is no. Posting a negative is tough, because there always might be something clever that I've missed, but here's a case:
Possible interface engines are xlrd/xlwt/xlutils
, openpyxl
, and xlsxwriter
. None will work for your purposes, as xlrd/wt
don't support all formulae, xlsxwriter
can't modify existing xlsx
files, and openpyxl
loses images and charts.
Since I often need to do this, I've taken to only writing simple output to a separate file and then calling the win32api directly to copy the data between the workbooks while preserving all of my colleague's shiny figures. It's annoying, because it means I have to do it under Windows instead of *nix, but it works.
If you're working under Windows, you could do something similar. (I wonder if it makes sense to add a native insert option using this approach to help people in this situation, or if we should simply post a recipe.)
P.S.: This very problem has annoyed me enough from time to time that I've thought of learning enough of the modern Excel format to add support for this to one of the libraries.
P.P.S.: But since ignoring things you're not handling and returning them unmodified seems easy enough, the fact that no one seems to support it makes me think there are some headaches, and where Redmond's involved I'm willing to believe it. @john-machin would know the details, if he's about..