gpt4 book ai didi

Python ExcelWriter 格式 'all borders'

转载 作者:太空宇宙 更新时间:2023-11-04 00:00:09 26 4
gpt4 key购买 nike

我有这个enter image description here

我要这个

enter image description here

我查看了文档,但看不到可以实现此目的的函数。

最佳答案

您可以使用类似这样的方式向列添加格式(您必须调整样式以获得所需的厚度):

import pandas as pd
import numpy as np
import xlsxwriter

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c'])
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
workbook = writer.book
worksheet = writer.sheets['Sheet1']

border_fmt = workbook.add_format({'bottom':5, 'top':5, 'left':5, 'right':5})
worksheet.conditional_format(xlsxwriter.utility.xl_range(0, 0, len(df), len(df.columns)), {'type': 'no_errors', 'format': border_fmt})
writer.save()

这里是格式示例的链接:https://xlsxwriter.readthedocs.io/format.html

关于Python ExcelWriter 格式 'all borders',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55928797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com