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

Source: Internet
Author: User
There is no better way to write excel,lorinnn search on the Internet and later use of the method is to use a third-party library xlutils to achieve this function, the main idea is to first copy the sheet and then again on the basis of appending and saving to a new Excel document.

Using 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", "W Oman ",", "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")
  

Before the Chase

Name Sex age  countryjim  Mans  usahmm  woman Chnlilei  Man

After the pursuit of writing

Name  sex age  countryjim  Mans  usahmm  woman chnlilei man  Chnann  woman
  • 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.