Xlxwriter标题样式

时间:2017-06-12 12:15:44

标签: pandas xlsxwriter

我使用以下方法为excel文件生成自定义标头。 当在Jupyter Note book中运行时,标题会正确生成,但是当作为" .py"执行时。文件标头格式丢失。我执行的同一版本的python和xlsxwriter

import pandas as pd
import numpy as np
import xlsxwriter
import pandas.io.formats.excel

df = pd.DataFrame(np.random.randint(0,100,size=(30, 4)), columns=list('ABCD'))
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')

df.to_excel(writer,index=False)
workbook  = writer.book
worksheet = writer.sheets['Sheet1']

pandas.io.formats.excel.header_style = None

header_format = workbook.add_format({'text_wrap': True,
                                     'font_size':11,
                                     'bold': True,
                                     'align': 'center',
                                     'valign': 'top',
                                     'fg_color': '#D7E4BC',
                                     'border': 1})

worksheet.set_row(0,40, header_format)

workbook.close()
writer.save()

0 个答案:

没有答案