I am having problems appending issues appending data to an xls
file. Long story short, I am using a program to get some data from something and writing it in an xls
file.
If I run the script 10 times, I would like the results to be appended to the same xls file.
My problem is that I am forced to use Python 3.4 and xlutils
is not supported, so I cannot use the copy function.
I just have to use xlwt
/ xlrd
. Note, the file cannot be a xlsx
.
Is there any way i can do this?
I would look into using openpyxl, which is supported by Python 3.4. An example of appending to a file can be found https://openpyxl.readthedocs.org/en/default/ . Please also see: How to append to an existing excel sheet with XLWT in Python . Here is an example that will do it. Assuming you have an Excel sheet called sample.xlsx:
from openpyxl import Workbook, load_workbook
# grab the active worksheet
wb = load_workbook("sample.xlsx")
ws = wb.active
ws.append([3])
# Save the file
wb.save("sample.xlsx")
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.