UserWarning: "Cannot parse header or footer so it will be ignored" on loading xlsm file
Asked Answered
F

4

5

Trying to open xlsm file using python

Below is the code :

import libraries
import openpyxl
from openpyxl import load_workbook
from openpyxl import Workbook
from openpyxl.styles import colors
from openpyxl.styles import Color, PatternFill, Font, Border

#path of the source sheet
path = "C:\DATA\PYTHON\Practise\SysTSAutSW300PFCRebuildDemo.xlsm"
wb1 = load_workbook(path)

sheet = wb1.get_sheet_by_name('PFC_Rebuild')

celldata = sheet['L33']

print celldata

It gives the below error :

Warning (from warnings module): File "C:\Python27\lib\site-packages\openpyxl\worksheet\header_footer.py", line 49 warn("""Cannot parse header or footer so it will be ignored""") UserWarning: Cannot parse header or footer so it will be ignored

Frankish answered 9/1, 2019 at 9:16 Comment(6)
It's not an error, it's a warning. It's telling you that openpyxl lacks support for some of the features of the file you are trying to open. Whether that matters or not depends on what you are trying to do and whether you consider headers and footers important. Remember, openpyxl is a volunteer open-source project. The only software that can be guaranteed to do everything that Excel does is Excel itself.Wicklund
Please don't put code in comments: it's impossible to read. If you want to amend the code in the question, edit the question.Wicklund
Yup, Thanks Got it. Sorry about the code in commentsFrankish
Relevant python-openpyxl-excel-file-reading-errorYeast
@Wicklund I face the same problem: it's a warning but the consequence is, that I cannot load a workbook correctly.Aircrewman
@Aircrewman Then maybe try making a copy of the workbook, that leaves out the feature complained of, and have your program load the simplified version instead. If that isn't a solution, then consider proposing a feature request to the openpyxl project.Wicklund
R
8

"""Cannot parse header or footer so it will be ignored"""

The warning occurred because you have an header or footer on your excel file that can't be parsed by openpyxl. If you want to get rid of the warning, you can remove the header and footer from the excel file with

File -> Info -> Check for Issues -> Inspect Document -> Remove your header and footer.

Rescue answered 24/8, 2019 at 0:2 Comment(0)
F
3

To get rid of this warning, change your load_workbook call to this:

wb1 = load_workbook(filename=path, read_only=True)
Fortify answered 15/5, 2020 at 10:40 Comment(1)
This works, but ... you can't then get at the value of cells, it seems (you certainly can't use the offset function).Grackle
H
3

You can influence the UserWarings using the warnings module. Also see Ignore UserWarning from openpyxl using pandas

import warnings
warnings.filterwarnings('ignore', category=UserWarning, module='openpyxl')
Heuer answered 25/1, 2023 at 10:52 Comment(0)
E
0

The issue generally occurs when the sheet is formatted with a "Freeze Pane".

See Menu -> View -> Freeze Panes

Removing the Panes in Excel will resolve the issue.

Elixir answered 23/8, 2024 at 9:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.