Example of using a third-party library xlutils in Python to append data to an Excel file

Source: Internet
Author: User
This article mainly introduces how to use a third-party library xlutils in Python to append and write an Excel file. This article provides an example of append and write effect, if you want to write an Excel file, you can see that there is no better way to search for it. lorinnn found it online and then used 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.