use*_*972 36 python cell openpyxl
我遇到了这个问题,因为cell.value函数返回用于单元格的公式,我需要在操作后提取Excel提供的结果.
谢谢.
好吧,我想我找到了解决办法; 显然要访问cell.internal值,你必须先在工作表中使用iter_rows(),这是一个"RawCell"列表.
for row in ws.iter_rows():
for cell in row:
print cell.internal_value
Run Code Online (Sandbox Code Playgroud)
Iul*_*ana 69
就像Charlie Clark已经建议您data_only在True加载工作簿时可以启用:
from openpyxl import load_workbook
wb = load_workbook("file.xlsx", data_only=True)
sh = wb["Sheet_name"]
print(sh["x10"].value)
Run Code Online (Sandbox Code Playgroud)
祝好运 :)
Cha*_*ark 27
从代码看起来你正在使用优化的阅读器:read_only=True.您可以data_only=True在打开工作簿时使用标志在提取公式及其结果之间切换.
internal_value是一个私有属性,用于仅指代Excel使用的(无类型)值,即.1900年的纪元数字用于日期而不是Python形式.自从首次询问此问题以来,它已从库中删除.
You can try following code.Just provide the excel file path and the location of the cell which value you need in terms of row number and column number below in below code.
from openpyxl import Workbook
wb = Workbook()
Dest_filename = 'excel_file_path'
ws=wb.active
print(ws.cell(row=row_number, column=column_number).value)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72345 次 |
| 最近记录: |