简单地说,我想将一个Excel文件的所有格式保存到另一个Excel文件中。但是,尽管使用了formatting_info=True标志,格式只显示在已更改行中所有未更改的单元格中。有什么建议吗?
import xlrd, xlutils
from xlrd import open_workbook
from xlutils.copy import copy
inBook = xlrd.open_workbook(r"path/to/file/format_input.xls", formatting_info=True, on_demand=True)
outBook = xlutils.copy.copy(inBook)
outBook.get_sheet(0).write(0,0,'changed!')
outBook.save(r"path/to/file/format_output.xls")在这里输入图像描述


发布于 2015-01-30 16:49:53
在使用openpyxl时,我遇到了类似的问题--由于某些原因,这在可用的模块中似乎处理得不太好。在输入数据之后,我只需根据需要重新设置单元格的样式,使用如下语法:
#Formatting
from openpyxl.styles import Style, Color, PatternFill, Alignment, Font, NumberFormat
#Allows for conditional formatting
from openpyxl.formatting import CellIsRule #Allows for Conditional Formatting
for cell in changed_cells:
cell.style = Style(fill=PatternFill(patternType='solid', fgColor=Color('FFff8888')),
font=Font(name="Arial",size=11),
alignment=Alignment(horizontal="center"))有关用xlrd实现这类事情的语法的信息可以找到这里。
https://stackoverflow.com/questions/28240254
复制相似问题