Need to generate the corresponding DOCX,XLSX file from the database read log to make corresponding records
So it's natural to use these two libraries.
However, these libraries are widely used, and any effort to perform repetitive operations on Word,excel files can be done using Python to help us
Xlsxwriter Library
article Structure :
First, Xlsxwriter basic usage, add data to the xlsx file
Second, xlsxwriter format processing, the data to be added to the appropriate format, added to the xlsx file
Three
First, Xlsxwriter basic usage, add data to the xlsx file
Xlsxwriter can manipulate xlsx format files
Note: Xlsxwriter can only create new files and cannot modify existing files. If you create a new file with the same name as the original file, the original file is overwritten
Installation: sudo pip install Xlsxwriter
1 #!/usr/bin/python2 #Coding:utf-83 4 ImportXlsxwriter5 6 #Create a new xlsx file (if the original file with the same name is overwritten)7Workbook = Xlsxwriter. Workbook ("expenses01.xlsx")8 9 #create a new form with the default name of "Sheet1" and enter a character parameter to specify a nameTenWorksheet =Workbook.add_worksheet () One AExpenses = ( -['Rent', 1000], -[' Gas', 100], the[' Food', 300], -['Gym', 50], - ) - + #worksheet default is counting from 0 rows, 0 columns -row =0 +Col =0 A at #The Worksheet.write method writes data to the XLSX table - #The parameters are: line number, column number, data - forItem, Costinch(expenses): - worksheet.write (Row, col, item) -Worksheet.write (Row, col + 1, cost) -Row + = 1 in - #explicitly close the workbook, if not explicitly specified, then automatically close when the scope ends toWorkbook.close ()
Effect Show:
docx, Xlsxwriter Library, using Python to manipulate docx, xlsx format files