sarizal
sarizal

Reputation: 49

Openpyxl TypeError: Value must be a sequence when trying to load existing workbook

This used to work but doesn't anymore. Openpyxl version 3.0.5

import csv, traceback, openpyxl,re, glob, datetime, calendar, os
from imbox import Imbox

os.chdir('c:\\users\\sariz\\onedrive\\desktop')
wb = openpyxl.load_workbook('budget sheet.xlsx')
Output: TypeError: Value must be a
sequence at the 95 (the final line here)

This an example of a sheet that is outputted by the program from when it worked:

[sheet demo example]

Upvotes: 2

Views: 5751

Answers (3)

Eliana
Eliana

Reputation: 1

I had the same issue but updating to version 3.0.7 (or higher) may help. I have an Excel file with pivot tables and formulas and version 3.0.5 could not read it but 3.0.7 can.

Upvotes: 0

sarizal
sarizal

Reputation: 49

YES!! You cracked it! thank you so much @Dr. Xavier for the help and for being so patient! Apparently openpyxl can only read excel sheets that are mainly unformatted, i think it had to do with me using tables. After I created a new blank excel sheet for it to read and enter data it worked just like before. Thank you so much!!

Upvotes: 2

Ahmed
Ahmed

Reputation: 914

To be honest with you, I turned to be confused. So, I decided to run the same code you're are running and display to you the output and the traced output of your running code;

Code Syntax

import openpyxl as xl
import os

os.chdir('C:\\Users\\user\\Desktop\\BigDataWork')
wb = xl.load_workbook('x x.xlsx')

sheet = wb.active

cell = sheet.cell(row =1, column= 1)
print(cell)
print('The first value in the Excel file is  ', cell.value)

Code Traced output

Print Output:
<Cell 'PolicyData'.A1>
The first value in the Excel file is  Policy
Variables:
-{
    cell: -{
        py/object: "openpyxl.cell.cell.Cell",
        row: 1,
        column: 1,
        _value: "Policy",
        data_type: "s",
        parent: "<Worksheet \"PolicyData\">",
        _hyperlink: null,
        _comment: null,
        _style: +{2 items}
    },
    sheet: "<Worksheet \"PolicyData\">",
    wb: "<openpyxl.workbook.workbook.Workbook object at 0x0000021B69DBE7F0>"
}
1060 ms

Excel Simple Values >> The reason for asking about that is maybe you're an error in your budget sheet.xlsx

enter image description here

Upvotes: 0

Related Questions