I'm trying to open a column in excel and move all the values from it's cells into a list.
def open_excel(col, excel_file):
open_file = openpyxl.load_workbook(excel_file)
sheet_object = open_file.get_sheet_names()[0]
cell_vals = []
col_num = column_index_from_string(start_col)
for cell in sheet_object.columns[col_num]:
cell_vals.append(str(cell.value))
After I run that I get the error:
builtins.AttributeError: 'str' object has no attribute 'columns'
But I've already imported everything as well.
Here's what I've imported:
import openpyxl
from openpyxl.cell import get_column_letter, column_index_from_string
import numpy as np
import matplotlib.pyplot as plt
You have a sheet name, a string object, assigned to
sheet_object
:get_sheet_names()
returns a sequence of strings, not of objects; it just returnsself.sheetnames
. You would have to use that name to get the actual sheet object:You could more easily grab the first active work sheet with: