Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

python - Error writing to an existing xlsm file using OPENPYXL -> xml.etree.ElementTree.ParseError: mismatched tag: line 42, column 8

I want to write / change a value to a single cell of an existing xlsm file (let's call it filename.xlsm), maintaining all macros and properties of the original xlsm file.

filename.xlsm has several sheets. I wish to write the value 4 in cell E3 of sheet 'Sup'.

I get the error "xml.etree.ElementTree.ParseError: mismatched tag: line 42, column 8"

The PYTHON code

import pandas as pd 
import numpy as np
import openpyxl

InputExcelfile = openpyxl.load_workbook('filename.xlsm', keep_vba=True)

sup_sheet = InputExcelfile['Sup']

sup_sheet['E3'] = 4

InputExcelfile.save('filename.xlsm')

I have tried deleting several sheets to see if the error disappears, but this only happens with this sheet.

After running the program and getting the error, I try accessing the Excel and get the error:

Excel error message

Help would be very much appreciated.

Many thanks.

question from:https://stackoverflow.com/questions/66054950/error-writing-to-an-existing-xlsm-file-using-openpyxl-xml-etree-elementtree-p

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...