Recently, you need Python to manipulate an Excel table and read the contents of the table into a database. So I searched for relevant information. There are several libraries that can operate Excel sheets:

  • openpyxl

This is the recommended library. It can read and write files ending in.xlsx in Excel 2010 and above.

  • xlsxwriter

This supports.xlsx, but only writes, formatting, etc., not reads.

  • xlrd

This supports reading data and supports files ending in XLS, which is the older format.

  • xlwt

This corresponds to the above, supports writing books and formatting data, and supports XLS ending file formats.

  • xlutils

This is a combination of the XLRD and XLWT libraries.

After comparison, I still choose the library OpenPyXL. The following is a description of the use of this library

Public number [intelligent manufacturing column], after the technical articles will be sent in the column. The code for this article is hosted on GitHub. Click the link

  • Create a workbook
From openpyxl import Workbook wb = Workbook() ws = wb. Ws1 = New sheet ws1. Title = "New title" # get the table by name, and the second represents a table ws1.save('your_name.xlsx') # save
  • Reads the contents of a workbook
From openpyxl import load_workbook wb = load_workbook('myname.xlsx') print wb.get_sheet_names() #
  • Simple Usage
from openpyxl import Workbook from openpyxl.compat import range from openpyxl.cell import get_column_letter wb = Workbook() SELECT * FROM 'empty_book.xlsx' SELECT * FROM 'empty_book.xlsx' SELECT * FROM 'empty_book.xlsx' LIMIT 1 For row in range(1,40): Ws1.append (range(600)) ws2 = wb.create_sheet(title="Pi") ws2['F5'] = 3.14 ws3 = Wb.create_sheet (title="Data") wb.create_sheet(title="Data") wb.create_sheet(title="Data") wb.create_sheet(title="Data") For col in range (27,) : _=ws3.cell(column=col,row=row,value="%s" % get_column_letter(col)) #_ =ws3.cell(column=col,row=row,value="%s" % get_column_letter(col)) # Wb.save (filename=dest_filename) #