CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day15/excel1.py
Views: 729
1
"""
2
创建Excel文件
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-26
7
"""
8
from openpyxl import Workbook
9
from openpyxl.worksheet.table import Table, TableStyleInfo
10
11
workbook = Workbook()
12
sheet = workbook.active
13
data = [
14
[1001, '白元芳', '男', '13123456789'],
15
[1002, '白洁', '女', '13233445566']
16
]
17
sheet.append(['学号', '姓名', '性别', '电话'])
18
for row in data:
19
sheet.append(row)
20
tab = Table(displayName="Table1", ref="A1:E5")
21
22
tab.tableStyleInfo = TableStyleInfo(
23
name="TableStyleMedium9", showFirstColumn=False,
24
showLastColumn=False, showRowStripes=True, showColumnStripes=True)
25
sheet.add_table(tab)
26
workbook.save('./res/全班学生数据.xlsx')
27
28