Openpyxl:'Worksheet'对象没有属性'值' [英] Openpyxl: 'Worksheet' object has no attribute 'values'
问题描述
我的目标描述如下:如何在大熊猫/ python中查看excel电子表格的公式?
Openpyxl应该支持这个,但是我无法使导入功能正常。任何人发现错误?
从openpyxl导入load_workbook
从openpyxl.utils导入pandas作为pd
。 dataframe import dataframe_to_rows
df = pd.DataFrame()
wb = load_workbook(filename ='name.xlsx')
sheet_names = wb.get_sheet_names()
name = sheet_names [0]
sheet_ranges = wb [name]
df = pd.DataFrame(sheet_ranges.values)
> AttributeError:'Worksheet'对象没有属性'value'
(注意:答案的确切实现链接的问题产生 KeyError:'Worksheet范围名称不存在'。
我的代码解决了这个问题,但是如上所述被卡住。)
import openpyxl
print(openpyxl .__ version__)
工作表的值属性仅从 2.4.0-a1(2016-04-11)添加
My goal is to read in an excel file and view the codes in a pandas dataframe (i.e. '= A3') rather than the resulting values from excel executing the codes, which is the pandas default if read in using pandas.
My goal was described here: How can I see the formulas of an excel spreadsheet in pandas / python?
Openpyxl is supposed to support this, but I can't get the import to function correctly. Anyone spot the error?
import pandas as pd
from openpyxl import load_workbook
from openpyxl.utils.dataframe import dataframe_to_rows
df = pd.DataFrame()
wb = load_workbook(filename = 'name.xlsx')
sheet_names = wb.get_sheet_names()
name = sheet_names[0]
sheet_ranges = wb[name]
df = pd.DataFrame(sheet_ranges.values)
> AttributeError: 'Worksheet' object has no attribute 'values'
(Note: the exact implementation of the answer at the linked question yields KeyError: 'Worksheet range names does not exist.'
My code above resolved this, but then gets stuck as described.)
Check your version of openpyxl, It seems you have an older version.
import openpyxl
print(openpyxl.__version__)
Values property for worksheets were added only from 2.4.0-a1 (2016-04-11)
这篇关于Openpyxl:'Worksheet'对象没有属性'值'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!