python xlutils.copy_使用python的xlrd,xlwt和xlutils.copy保留样式

本文提供了一个使用Python的xlrd、xlwt和xlutils.copy库来复制Excel文件并保留样式的代码示例。首先创建了一个带有不同格式的输入文件,然后通过xlutils.copy2函数进行复制,更新内容但保持原始格式不变。
摘要由CSDN通过智能技术生成

慕盖茨1488219

以下是我将作为针对xlutils 1.4.1的补丁提出的代码使用示例# coding: asciiimport xlrd, xlwt# Demonstration of copy2 patch for xlutils 1.4.1# Context:# xlutils.copy.copy(xlrd_workbook) -> xlwt_workbook# copy2(xlrd_workbook) -> (xlwt_workbook, style_list)# style_list is a conversion of xlrd_workbook.xf_list to xlwt-compatible styles# Step 1: Create an input file for the demodef create_input_file():

    wtbook = xlwt.Workbook()

    wtsheet = wtbook.add_sheet(u'First')

    colours = 'white black red green blue pink turquoise yellow'.split()

    fancy_styles = [xlwt.easyxf(

        'font: name Times New Roman, italic on;'

        'pattern: pattern solid, fore_colour %s;'

         % colour) for colour in colours]

    for rowx in xrange(8):

        wtsheet.write(rowx, 0, rowx)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值