Python Basics of Excel

Source: Internet
Author: User

Python reads Excel primarily Xlrd,python writes and creates Excel files that can be used with XLWT, XLSXWRITER,XLWT support Office2013,xlsxwriter support office2013 and more.

Create and read Excel code testxlrd.py:

#Coding=utf-8ImportxlrdImportXLWT#reading data through XLRDdefreadexcel (): FilePath="d:\\a.xlsx"Data=Xlrd.open_workbook (filePath) Table0=data.sheets () [0] nrows=table0.nrows forIinchRange (nrows):ifi = = 0:#Skip the first line            Continue        Print(Table0.row_values (i) [: 5])#take the first 5 columns#writing data through XLWTdefwriteexcel (): Workbook= XLWT. Workbook ()#Note the beginning of workbook W to capitalizeSheet1 = Workbook.add_sheet ('Sheet1')    #writing data to a sheet pageSheet1.write (0,0,'User name') sheet1.write (0,1,'Email') Sheet1.write (1, 0,'Tom') Sheet1.write (1, 1,'[email protected]') Workbook.save ('D:\\b.xls')    Print('Create Excel file complete! ')

Calling code:

Python 3.6.1 (V3.6.1:69C0DB5, Mar, 17:54:52) [MSC v.1900 32bit (Intel)] on Win32type"Copyright","credits" or "license ()"  forMore information.>>> fromTestxlrdImport*>>>writeexcel () Create Excel file complete! >>>readexcel () [1.0,'Joyet1'][2.0,'Joyet2'][3.0,'Joyet3'][4.0,'Joyet4'][5.0,'Joyet5'][6.0,'Joyet6'][7.0,'Joyet7'][8.0,'Joyet8'][9.0,'Joyet9']>>>

Python Basics of Excel

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.