创建excel表格
import xlsxwriter
excel = xlsxwriter.Workbook(excel_path)
创建sheet页
sheet = excel.add_worksheet(sheet)
设置excel相关样式
def set_style_xlswriter(self, workbook, color="white"):
"""
设置表格单元格样式
:workbook:xlswriter创建的表格
:color:单元格颜色
"""
try:
workfomat = workbook.add_format()
workfomat.set_text_wrap()
workfomat.set_align('center')
if color != "white":
workfomat.set_bg_color(color)
return workfomat
except Exception as e:
device_monitor_output_log.error("set_style_xlswriter error:{}".format(e))
写入表格内容(非全部)
style = self.set_style_xlswriter(excel, color="yellow")
head = ["A","B","C", "D"]
sheet.write_row("C1", head, style)
sheet.write("A1:B2", data,style)
sheet.merge_range("A1:B2", data,style)
sheet.set_column("A1:B1", 10)
sheet.insert_image("D4",image_path)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)