简体   繁体   中英

using openpyxl to change an excel document without removing existing data and graphs

I'm trying to use python to copy data from a dat file to an excel template with openpyxl. I tried doing a few tests to play with a template and found that when I saved the file it deleted most of the existing cells and all of the graphs. I read in another question that openpyxl might not be good for editing existing spreadsheets. Is there a better option or a way to get this one to work?

This is the code I was working on just to see if I could edit the spreadsheet:

import openpyxl
wb=openpyxl.load_workbook('file.xlsm', keep_vba=True)
A=wb.get_sheet_by_name("A")
g=A['F24'].value
print g
A['A1'].value=g
print A['A1'].value
wb.save('file2.xlsm')

When I opened file2 most of the formatting, data, and all the graphs were gone.

Edit:So I'm trying out xlwings and I can't find a good tutorial or list of terms used. Anyone know where I can find that?

从openpyxl的2.5版本开始,这是可能的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM