cell - python xlrd模块 怎么获得单元格格式信息

查看:1136
本文介绍了cell - python xlrd模块 怎么获得单元格格式信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我想获取一个excle单元格的格式来设置另外一个excle的格式,但不知道怎么获取excle的单元格格式信息。

workbook_A = xlrd.open_workbook(self.file_A,ragged_rows=True)
table_A = workbook_A.sheet_by_name(self.sheetName)
nrows_A = table_A.nrows
nclos_A = table_A.ncols

解决方案

import xlrd
from xlutils.filter import process, XLRDReader, XLWTWriter
def copy2(wb):
    w = XLWTWriter()
    process(XLRDReader(wb, 'unknown.xls'), w)
    return w.output[0][1], w.style_list

rb = xlrd.open_workbook('C:\\Users\\sa\\Desktop\\1.xls', formatting_info=True, on_demand=True)
wb, s = copy2(rb)
wbs = wb.get_sheet(0)
rbs = rb.get_sheet(0)
styles = s[rbs.cell_xf_index(0, 0)]
rb.release_resources()  #关闭模板文件

wbs.write(0, 0, 'aa', styles)
wb.save("C:\\Users\\sa\\Desktop\\2.xls")

这篇关于cell - python xlrd模块 怎么获得单元格格式信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆