可以安装xlsxwriter库
看简例:
import xlsxwriter
# 创建新表格
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
# 表格的内容
expenses = (
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
)
# 想象表格的布局,坐标 0,0 对应 A,1
row = 0
col = 0
# 填充每个单元格
for item, cost in (expenses):
worksheet.write(row, col, item)
worksheet.write(row, col + 1, cost)
row += 1
workbook.close()
python可以用openpyxl包来读取和写入xlsx文件。