總而言之,我從原始 csv 文件中生成了一些匯總統計數據。我還將此摘要保存到了excel中。我現在需要通過格式化使這份報告看起來很漂亮。我知道將 CSS 樣式應用于數據框,但無法將這些格式導出到 excel?;蛘?,我嘗試在 xlsxwriter 中使用格式化功能取得不同程度的成功。導出后有沒有辦法格式化這個數據框?out.to_excel(writer, sheet_name='Dist-Market',startrow = 3 , startcol = 3)def frmt_tbl(ws,rng): ws.set_column(rng, 30)
1 回答

米琪卡哇伊
TA貢獻1998條經驗 獲得超6個贊
以下對我有幫助,我認為其他人可能也會覺得它有用。
https://xlsxwriter.readthedocs.io/working_with_pandas.html
# Add some cell formats.
format1 = workbook.add_format({'num_format': '#,##0.00'})
format2 = workbook.add_format({'num_format': '0%'})
# Set the column width and format.
worksheet.set_column('B:B', 18, format1)
# Set the format but not the column width.
worksheet.set_column('C:C', None, format2)
添加回答
舉報
0/150
提交
取消