Three tool kits
The Python three Toolkit for Excel works as follows
xlrd
: read-related operations on Excel
xlwt
: Write-related operations on Excel
xlutils
: Integration of Excel read and write operations
Note that it can only be manipulated .xls
and cannot be manipulated .xlsx
.
These three toolkits are available for download directly using PIP:
sudo pip install xlrdsudo pip install xlwtsudo pip install Xlutils
XLS file Write-in
XLWT can only create a completely new Excel file, and then write to and save the file.
But most of the time we want to read in an Excel file and then modify or append it, and then it needs to be xlutils.
Simple use of xlutils
The following demo is to append content to an Excel file:
fromXlrdImportOpen_workbook fromXlutils.copyImportCopyrexcel= Open_workbook ("Collection.xls")#read an Excel file using the method provided by Wlrdrows = Rexcel.sheets () [0].nrows#use the method provided by WLRD to get the number of rows you have nowExcel = Copy (Rexcel)#convert XLRD objects to XLWT objects using the Copy method provided by XlutilsTable = Excel.get_sheet (0)#get the sheet you want to manipulate by using the Xlwt object methodvalues = ["1","2","3"]row=rows forValueinchvalues:table.write (row, 0, value)#XLWT The Write method of the object, the parameters are row, column, valueTable.write (row, 1,"haha") table.write (row,2,"Lala") Row+ = 1Excel.save ("Collection.xls")#The XLWT object is saved by overwriting the original Excel
Is the way Python reads, writes, and writes Excel files