我正在编写一个python脚本,使用xlrd从excel表中读取数据.工作表中的几个单元格用不同颜色突出显示,我想识别单元格的颜色代码.有没有办法做到这一点?一个例子将非常感激.
我有简单的代码来复制xlutils,xlrd,xlwt文件(从python-excel.org下载新的库)而没有丢失格式.我有一个错误如下:
from xlwt.Workbook import *
from xlwt.Style import *
from xlrd import open_workbook
from xlutils.copy import copy
import xlrd
style = XFStyle()
rb = open_workbook('file_master.xlsx', formatting_info=True)
wb = copy(rb.get_sheet(0))
new_book = Workbook()
w_sheet = wb.get_sheet(0)
w_sheet.write(6,6)
wb.save('new_file_master.xls')
Run Code Online (Sandbox Code Playgroud)
错误:
raise NotImplementedError("formatting_info=True not yet implemented")
NotImplementedError: formatting_info=True not yet implemented
Run Code Online (Sandbox Code Playgroud)
你能帮我解决一下如何解决这个问题,还是让它发挥作用?
我是python的新手,我正在尝试从Excel工作表中读取信息以生成图形。到目前为止,我正在嵌套的for循环中使用xlrd库的最新版本(0.9.4)从每个单元格获取值。但是,我不确定如何访问每个单元格的格式信息
例如,如果单元格的格式设置为在excel文件中显示为货币,则使用sheet.cell(row, column).valuexlrd中的标准只会返回5.0而不是$5.00
我在这里发现,可以在打开工作簿时将formatting_info参数设置为true以便查看某些格式信息,但是我主要使用的是excel 2013,并且我的excel工作表默认情况下另存为.xlsx文件。根据GitHub上的此问题,尚未为.xlsx文件实现对formatting_info的支持。
有什么方法可以使用formatting_info标志,或者可以使用其他任何方式检测何时使用了格式(特别是货币)来在我的图形中反映出来?我知道可以将.xlsx文件转换为.xls文件,例如此处所示,但我担心信息/格式丢失。
我正在尝试填充 Excel 文件的一些核心属性字段(即主题、类别和标题字段),但找不到这样做的方法。
我能够使用 docx 模块使用 .docx 文件完成此操作,如下所示:
doc = docx.Document(file)
name = doc.tables[1]._cells[43].text
data = doc.tables[0]._cells[1].text
numbers = re.findall('\d{9}', data)
doc.core_properties.title = numbers[0]
doc.core_properties.category = numbers[1]
doc.core_properties.subject = name
doc.save(file)
Run Code Online (Sandbox Code Playgroud)
是否有类似的方法可以使用 .xlsx 文件执行此操作,还是我不走运?
python ×4
excel ×3
xlrd ×3
fileinfo ×1
python-2.7 ×1
python-3.x ×1
xls ×1
xlsx ×1
xlutils ×1
xlwt ×1