python复制和编辑excel

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#coding=utf-8

import os

import os.path

import sys

from xlrd import open_workbook

from xlutils.copy import copy

from g315.config import conf

import chardet

import re

p=pile(r'(?i){{(.*?)}}')

source_file_mold = os.path.join(conf.APP_DIR, "public/excel/source/module.xls") target_file_mold = os.path.join(conf.APP_DIR, "public/excel/target/result.xls")

import xlrd

import xlwt

from xlrd import open_workbook,cellnameabs

from xlutils.copy import copy

def copy_xf(rdbook,rdxf):

"""

clone a XFstyle from xlrd XF class,the code is copied from xlutils.copy module """

wtxf = xlwt.Style.XFStyle()

#

# number format

#

wtxf.num_format_str = rdbook.format_map[rdxf.format_key].format_str

#

# font

#

wtf = wtxf.font

rdf = rdbook.font_list[rdxf.font_index]

wtf.height = rdf.height

wtf.italic = rdf.italic

wtf.struck_out = rdf.struck_out

wtf.outline = rdf.outline

wtf.shadow = rdf.outline

wtf.colour_index = rdf.colour_index

wtf.bold = rdf.bold #### This attribute is redundant, should be driven by weight wtf._weight = rdf.weight #### Why "private"?

wtf.escapement = rdf.escapement

wtf.underline = rdf.underline_type ####

# wtf.???? = rdf.underline #### redundant attribute, set on the fly when writing wtf.family = rdf.family

wtf.charset = rdf.character_set

=

#

# protection

#

wtp = wtxf.protection

rdp = rdxf.protection

wtp.cell_locked = rdp.cell_locked

wtp.formula_hidden = rdp.formula_hidden

#

# border(s) (rename ????)

#

wtb = wtxf.borders

rdb = rdxf.border

wtb.left = rdb.left_line_style

wtb.right = rdb.right_line_style

wtb.top = rdb.top_line_style

wtb.bottom = rdb.bottom_line_style

wtb.diag = rdb.diag_line_style

wtb.left_colour = rdb.left_colour_index

wtb.right_colour = rdb.right_colour_index

wtb.top_colour = rdb.top_colour_index

wtb.bottom_colour = rdb.bottom_colour_index

wtb.diag_colour = rdb.diag_colour_index

wtb.need_diag1 = rdb.diag_down

wtb.need_diag2 = rdb.diag_up

#

# background / pattern (rename???)

#

wtpat = wtxf.pattern

rdbg = rdxf.background

wtpat.pattern = rdbg.fill_pattern

wtpat.pattern_fore_colour = rdbg.pattern_colour_index

wtpat.pattern_back_colour = rdbg.background_colour_index

#

# alignment

#

wta = wtxf.alignment

rda = rdxf.alignment

wta.horz = rda.hor_align

wta.vert = rda.vert_align

相关文档
最新文档