Error code in Python

Hi i’m getting an error when trying to read an excel which is in (xlsx) format, this excel has links to other excels.
and same code works when i use .xls

error code image

Its impossible to say, because we can’t see the entire traceback.

What IDE are you using? It is displaying so much extra information that the important information is hidden.

If it works when you use .xls, and doesn’t work when you use .xlsx, then you should use .xls.

Without seeing the rest of the error, I cannot even guess what the problem is with the .xlsx file. Maybe it doesn’t exist?

Thank you for your reply, please note that Im new to Python and to this forum. Im not sure what you mean by IDE,
anyway i’m using Jupiter note book launched from Anaconda.

file exists in the mentioned path. i double checked.

if you want me to show the entire error report, i don’t know how to do it in this forum there is no option to attach a file

Copy and paste the code and the complete traceback. The code and the traceback should be posted wrapped in triple backticks to preserve the formatting.

For the code:

```python
if True:
    print(''Hello world!')
```

and for the traceback:

```
traceback stuff
```

It looks like a Jupyter notebook to me, a rather nice interactive Python
env with “cells” which are either markdown text or Python code, thus
providing a form of literate programming and also lending itself to be
the basis of an explained workflow for whatever purpose.

Cheers,
Cameron Simpson cs@cskk.id.au

For the Code

import pandas as pd

file_path = ‘D:\Mohommed.Althaf\Desktop\WIP\a.xlsx’
df = pd.read_excel(file_path)
print(df)

for the traceback:


ValueError Traceback (most recent call last)
Input In [54], in <cell line: 4>()
1 import pandas as pd
3 file_path = ‘D:\Mohommed.Althaf\Desktop\WIP\a.xlsx’
----> 4 df = pd.read_excel(file_path)
5 print(df)

File ~\Anaconda3\lib\site-packages\pandas\util_decorators.py:311, in deprecate_nonkeyword_arguments..decorate..wrapper(*args, **kwargs)
305 if len(args) > num_allow_args:
306 warnings.warn(
307 msg.format(arguments=arguments),
308 FutureWarning,
309 stacklevel=stacklevel,
310 )
→ 311 return func(*args, **kwargs)

File ~\Anaconda3\lib\site-packages\pandas\io\excel_base.py:457, in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, decimal, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
455 if not isinstance(io, ExcelFile):
456 should_close = True
→ 457 io = ExcelFile(io, storage_options=storage_options, engine=engine)
458 elif engine and engine != io.engine:
459 raise ValueError(
460 "Engine should not be specified when passing "
461 “an ExcelFile - ExcelFile already has the engine set”
462 )

File ~\Anaconda3\lib\site-packages\pandas\io\excel_base.py:1419, in ExcelFile.init(self, path_or_buffer, engine, storage_options)
1416 self.engine = engine
1417 self.storage_options = storage_options
→ 1419 self._reader = self._engines[engine](self._io, storage_options=storage_options)

File ~\Anaconda3\lib\site-packages\pandas\io\excel_openpyxl.py:525, in OpenpyxlReader.init(self, filepath_or_buffer, storage_options)
514 “”"
515 Reader using openpyxl engine.
516
(…)
522 passed to fsspec for appropriate URLs (see _get_filepath_or_buffer)
523 “”"
524 import_optional_dependency(“openpyxl”)
→ 525 super().init(filepath_or_buffer, storage_options=storage_options)

File ~\Anaconda3\lib\site-packages\pandas\io\excel_base.py:518, in BaseExcelReader.init(self, filepath_or_buffer, storage_options)
516 self.handles.handle.seek(0)
517 try:
→ 518 self.book = self.load_workbook(self.handles.handle)
519 except Exception:
520 self.close()

File ~\Anaconda3\lib\site-packages\pandas\io\excel_openpyxl.py:536, in OpenpyxlReader.load_workbook(self, filepath_or_buffer)
533 def load_workbook(self, filepath_or_buffer: FilePath | ReadBuffer[bytes]):
534 from openpyxl import load_workbook
→ 536 return load_workbook(
537 filepath_or_buffer, read_only=True, data_only=True, keep_links=False
538 )

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:317, in load_workbook(filename, read_only, keep_vba, data_only, keep_links)
290 “”“Open the given filename and return the workbook
291
292 :param filename: the path to open or a file-like object
(…)
313
314 “””
315 reader = ExcelReader(filename, read_only, keep_vba,
316 data_only, keep_links)
→ 317 reader.read()
318 return reader.wb

File ~\Anaconda3\lib\site-packages\openpyxl\reader\excel.py:281, in ExcelReader.read(self)
279 self.read_properties()
280 self.read_theme()
→ 281 apply_stylesheet(self.archive, self.wb)
282 self.read_worksheets()
283 self.parser.assign_names()

File ~\Anaconda3\lib\site-packages\openpyxl\styles\stylesheet.py:198, in apply_stylesheet(archive, wb)
195 return wb
197 node = fromstring(src)
→ 198 stylesheet = Stylesheet.from_tree(node)
200 if stylesheet.cell_styles:
202 wb._borders = IndexedList(stylesheet.borders)

File ~\Anaconda3\lib\site-packages\openpyxl\styles\stylesheet.py:103, in Stylesheet.from_tree(cls, node)
101 for k in attrs:
102 del node.attrib[k]
→ 103 return super(Stylesheet, cls).from_tree(node)

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py:83, in Serialisable.from_tree(cls, node)
79 continue
81 if hasattr(desc, ‘from_tree’):
82 #descriptor manages conversion
—> 83 obj = desc.from_tree(el)
84 else:
85 if hasattr(desc.expected_type, “from_tree”):
86 #complex type

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py:85, in NestedSequence.from_tree(self, node)
84 def from_tree(self, node):
—> 85 return [self.expected_type.from_tree(el) for el in node]

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py:85, in (.0)
84 def from_tree(self, node):
—> 85 return [self.expected_type.from_tree(el) for el in node]

File ~\Anaconda3\lib\site-packages\openpyxl\styles\fonts.py:109, in Font.from_tree(cls, node)
107 if underline is not None and underline.get(‘val’) is None:
108 underline.set(“val”, “single”)
→ 109 return super(Font, cls).from_tree(node)

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py:103, in Serialisable.from_tree(cls, node)
100 else:
101 attrib[tag] = obj
→ 103 return cls(**attrib)

File ~\Anaconda3\lib\site-packages\openpyxl\styles\fonts.py:75, in Font.init(self, name, sz, b, i, charset, u, strike, color, scheme, family, size, bold, italic, strikethrough, underline, vertAlign, outline, shadow, condense, extend)
69 def init(self, name=None, sz=None, b=None, i=None, charset=None,
70 u=None, strike=None, color=None, scheme=None, family=None, size=None,
71 bold=None, italic=None, strikethrough=None, underline=None,
72 vertAlign=None, outline=None, shadow=None, condense=None,
73 extend=None):
74 self.name = name
—> 75 self.family = family
76 if size is not None:
77 sz = size

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\nested.py:35, in Nested.set(self, instance, value)
32 raise ValueError(“Tag does not match attribute”)
34 value = self.from_tree(value)
—> 35 super(Nested, self).set(instance, value)

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\base.py:108, in Min.set(self, instance, value)
106 if value < self.min:
107 raise ValueError(‘Min value is {0}’.format(self.min))
→ 108 super(Min, self).set(instance, value)

File ~\Anaconda3\lib\site-packages\openpyxl\descriptors\base.py:87, in Max.set(self, instance, value)
85 value = _convert(self.expected_type, value)
86 if value > self.max:
—> 87 raise ValueError(‘Max value is {0}’.format(self.max))
88 super(Max, self).set(instance, value)

ValueError: Max value is 14

I think it’s complaining about a font size in the spreadsheet, but I can’t be sure.

Hi i’m getting an error when when the excel file is in (xlsx) format, this excel has links to other excels too.

and same code works for same file when I use .xls