'openpyxl - Load only a single sheet to prevent pivot tables from being involved
I want to load an .xlsx
file with openpyxl
:
from openpyxl import Workbook, load_workbook
wb = load_workbook(filename = "my_excel_file.xlsx", data_only = True)
However, it takes a very long time to load the workbook (>90 seconds for a file of 4 MB). I suspect that this is due to a pivot table in Sheet2
. There have been reported many cases where pivot tables have messed with previous versions of openpyxl
. With my current version (3.0.9
) the workbook can be loaded, but I assume that the pivot table is the reason why it is so slow.
Is there a way to load only a specific sheet, and not the entire .xlsx
file, so that I could avoid having to deal with the pivot table? Something like this:
wb = load_workbook(filename = "my_excel_file.xlsx", data_only = True, sheet = "Sheet1")
Or any other idea to avoid having the pivot table slow down everything?
Unfortunately, I cannot share the .xlsx
file due to confidentiality considerartions.
Also, I cannot remove the pivot table from the file because my colleagues work with it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|