python操作excel的代码怎么写

发布时间:2022-10-14 16:08:52 作者:iii
来源:亿速云 阅读:174

本篇内容主要讲解“python操作excel的代码怎么写”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python操作excel的代码怎么写”吧!

from datetime import datetime
import logging
import json
import xlwt
import os


class ExportReleaseNote():

    def __init__(self):
        self.date = datetime.now().strftime("%Y%m%d")
        self.savepath = os.path.join(BASE_DIR, "download")
        self.wb = xlwt.Workbook(encoding="utf-8")
        
        # 添加sheet
        self.ws = self.wb.add_sheet('Release Note')
        self.wski = self.wb.add_sheet('Known Issue')
        
        # 设置列宽
        self.ws.col(3).width = 256 * 80                                 
        self.wski.col(3).width = 256 * 80
        self.wski.col(5).width = 256 * 80
        
        # 字体
        self.font = xlwt.Font()
        self.font.bold = True                                                       # 加粗
        
        # 居中
        self.align = xlwt.Alignment()
        self.align.horz = xlwt.Alignment.HORZ_CENTER        # 水平居中
        self.align.vert = xlwt.Alignment.VERT_CENTER        # 垂直居中
        self.align.wrap = 1                             # 自动换行
        
        # 单元格边框
        self.border = xlwt.Borders()
        self.border.top = xlwt.Borders.THIN                         
        self.border.bottom = xlwt.Borders.THIN
        self.border.left = xlwt.Borders.THIN
        self.border.right = xlwt.Borders.THIN
        
        # 单元格颜色
        self.newstyle = xlwt.XFStyle()
        self.style = xlwt.XFStyle()
        self.pt = xlwt.Pattern()
        self.pt.pattern = xlwt.Pattern.SOLID_PATTERN
        self.pt.pattern_fore_colour = 22                # light gray
        
        # 应用到样式,在write的时候,配置样式,才生效
        # header
        self.style.pattern = self.pt
        self.style.font = self.font
        self.style.borders = self.border
        self.style.alignment = self.align
        # cell
        self.newstyle.alignment = self.align
        self.newstyle.borders = self.border
   
        # 设置行高
        self.ws.row(row).height_mismatch = True
        self.ws.row(row).height = 256 * 5

到此,相信大家对“python操作excel的代码怎么写”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. python 操作excel
  2. Python操作Excel工作簿的示例代码(\*.xlsx)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python excel

上一篇:如何利用redis实现倒计时任务

下一篇:jupyter启动报错module 'lib' has no attribute 'X509_-_FLAG_CB_ISSUER_CHECK'如何解决

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》