zw1ck
zw1ck

Reputation: 543

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?

Upvotes: 0

Views: 1458

Answers (1)

Charlie Clark
Charlie Clark

Reputation: 19507

This is possible starting with version 2.5 of openpyxl.

Upvotes: 1

Related Questions