In Python, xlutils, a third-party library, is used to append data to an Excel file,
At present, there is no better way to catch up with Excel. the method that lorinnn found on the Internet and will be used later is to use the third-party library xlutils to implement this function, the main idea is to copy a Sheet and then append it to a new Excel file.
Use xlutils
The code is implemented as follows:
# -*- coding: utf-8 -*- ''' Created on 2012-12-17 @author: walfred @module: XLRDPkg.write_append @description: ''' import os from xlutils.copy import copy import xlrd as ExcelRead def write_append(file_name): values = ["Ann", "woman", 22, "UK"] r_xls = ExcelRead.open_workbook(file_name) r_sheet = r_xls.sheet_by_index(0) rows = r_sheet.nrows w_xls = copy(r_xls) sheet_write = w_xls.get_sheet(0) for i in range(0, len(values)): sheet_write.write(rows, i, values[i]) w_xls.save(file_name + '.out' + os.path.splitext(file_name)[-1]); if __name__ == "__main__": write_append("./test_append.xls")
Pre-write
name sex age countryjim man 19 USAhmm woman 24 CHNlilei man 24 CHN
Post-write
name sex age countryjim man 19 USAhmm woman 24 CHNlilei man 24 CHNAnn woman 22 UK