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