-
Notifications
You must be signed in to change notification settings - Fork 158
Excel布局建议
YangZhang-GitHub edited this page Mar 1, 2021
·
4 revisions
# Row height
ws.row_dimensions[1].height = 102
for i in range(2, 2000 + 1):
ws.row_dimensions[i].height = 42
2. 将Alignment对象的wrap_text设置为True,就可以实现文字换行,如果文字换行后超过行高你通过 ws.row_dimensions[行号].height设置行高,建议60,列宽设置如下
# Col width
ws.column_dimensions['A'].width = 1.5
ws.column_dimensions['B'].width = 25.0
for i in range(ord('C'), ord('L')):
ws.column_dimensions[chr(i)].width = 15.0
# Img
img = Image("excelexporters/myems.png")
img.width = img.width * 0.85
img.height = img.height * 0.85
ws.add_image(img, 'B1')
line = LineChart()
line.title = \
'报告期成本 - ' + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" # 设置标题
labels = Reference(ws, min_col=2, min_row=table_row + 1, max_row=max_row) # 选择图表标签
line_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row) # 选择图表数据
line.add_data(line_data, titles_from_data=True) # 设置图表数据
line.set_categories(labels) # 设置图表标签
line_data = line.series[0]
line_data.marker.symbol = "circle" # 设置数据点样式
line_data.smooth = True # 设置折线平滑显示
line.x_axis.crosses = 'min' # 设置x标签显示位置,默认在y=0的位置显示,设置后在y=min(y)的位置显示
line.height = 8.25
line.width = 24
line.dLbls = DataLabelList()
line.dLbls.dLblPos = 't' # 设置数字在数据点上方显示
line.dLbls.showVal = True # 设置数据点显示数据
chart_col = 'B'
chart_cell = chart_col + str(current_row_number + 1 + 6 * i) # 设置图表插入位置
ws.add_chart(line, chart_cell)