Read and write Excel tables in Python

Source: Internet
Author: User

1 #!usr/bin/env python2 #-*-coding:utf-8-*-3 Importxlrd4 ImportXLWT5  fromXlutils.copyImportCopy6 ImportOS7 8data = Xlrd.open_workbook ('M3000.xls')#open an Excel table9Table = data.sheets () [0]#The sheet read by this method is read-only and cannot be writtenTenrows =table.nrows OneNcols =Table.ncols A  -datanew = copy (data)#copy a new Excel table -sheetnew = Datanew.get_sheet (0)#The sheet read by this method can be written the  - defrxcel (rows): -      forRinchRange (rows-1): -str = Table.cell (r+1,1). Value +num=len (str) -Sheetnew.write (r+1,7, num) +Os.remove ('M3000.xls')#The old Excel table was deleted ADatanew.save ('M3000.xls')#in the original position, re-save a table with the original table name at      - if __name__=='__main__': -Rxcel (rows)

Read and write Excel tables in Python

Related Article

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.