A simple example of reading an Excel file
#!/usr/bin/env python#-*-coding:utf-8-*-import xlrdfrom xlrd.book import bookfrom xlrd.sheet import Sheetfrom Xlrd.shee T Import Cellworkbook = Xlrd.open_workbook (' account information. xlsx ') Sheet_names = Workbook.sheet_names () # sheet = Workbook.sheet_by_ Name (' account information ') sheet = workbook.sheet_by_index (1) # Loops All rows of the Excel file for row in Sheet.get_rows (): # Loops All columns of a row for col in Row: # Gets the value in a cell print (col.value)
Second, a simple example of writing an Excel file
#!/usr/bin/env python#-*-coding:utf-8-*-import xlwtwb = xlwt. Workbook () sheet = wb.add_sheet (' Sheet1 ') for row in range ( 5): sheet.write (Row, col, ' {0} ' line {1} columns '. Format (row, col)) Wb.save (' Xxx.xls ') # more examples: https://github.com/python-excel/xlwt/tree/master/examples
Using Python to read and write Excel