python处理excel表格——openpyxl
openpyxl为三方库,需要 pip install openpyxl安装。
一、标准使用方式:
import os
import openpyxl
student_info = [{"name":"Jack", "gender":"man"}, {"name":"Mary", "gender":"woman"}]
excel_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'output/student.xlsx')
book = openpyxl.Workbook()
sheet = book.create_sheet('base_info')
book.save("student.xlsx")
book = openpyxl.load_workbook("student.xlsx")
sheet = book['base_info']
rows = sheet.max_row
columns = sheet.max_column
print(rows, columns)
for i in range(len(student_info)):
sheet.cell(row=i+1, column=1).value = student_info[i]['name']
sheet.cell(row=i+1, column=2).value = student_info[i]['gender']
book.save(excel_file)
print("create excel successful!")

|