Problem
I’m trying to get each page of “Page Break Preview”. Precisely speaking, I need to know which cells Page 1 contains, which cells Page 2 contains and so on.
Could you teach me how to realize this functionality in Python 3.12? I tried openpyxl
, but other libraries are welcome too.
Example (What I Tried)
I find openpyxl
has _print_area
variable, but this variable only returns the whole print area, which contains all pages, so I can’t know which page each cell belongs to.
As you can see the code and the screenshot, the result is A1:R50
, which contains both Page 1 and Page 2.
In this example, the expected result is something like {'Page1': 'A1:I50', 'Page2':'J1:R50'}
.
from openpyxl import load_workbook
workbook = load_workbook(filename="./sample_loader_data/sample.xlsx",
read_only=True,
data_only=True,
)
workbook.worksheets[0]._print_area # Result: <PrintArea [A1:R50]>