docling icon indicating copy to clipboard operation
docling copied to clipboard

Support page range conversion in xlsx documents

Open ceberam opened this issue 5 months ago • 2 comments

Problem

MsExcelDocumentBackend declares supports_pagination() = True and maps each worksheet to a sequential page number, but its convert() / _convert_workbook() methods do not respect the page_range parameter from in_doc.limits.page_range. All sheets are always processed regardless of the configured page range.

This is inconsistent with MsPowerpointDocumentBackend, which correctly applies page_range to filter slides during conversion.

Expected Behavior

When a user calls:

result = converter.convert("workbook.xlsx", page_range=(2, 4))

Only sheets 2–4 should be processed (where sheets are numbered sequentially starting from 1).

Proposed Implementation

In _convert_workbook(), apply page_range filtering to the sheet iteration, similar to how MsPowerpointDocumentBackend uses list slicing:

start_page, end_page = self.page_range
sheets = list(enumerate(workbook.worksheets))
selected_sheets = sheets[start_page - 1 : end_page]

This should also interact correctly with the existing sheet_names filter in MsExcelBackendOptions (i.e., page_range would apply to the filtered sheet list if sheet_names is set, or to all sheets otherwise).

Context

  • MsExcelDocumentBackend source: docling/backend/ms_excel_backend.py
  • Reference implementation: MsPowerpointDocumentBackend page_range handling
  • The infrastructure for passing page_range to the backend already exists via InputDocument.limits.page_range

ceberam avatar Jun 17 '26 07:06 ceberam

Hi Mr @ceberam, I'd love to work on this

My plan is to store self.page_range = in_doc.limits.page_range in __init__ (like the PPTX backend), then in _convert_workbook() apply the range after the existing sheet_names filter, so it stays consistent with page_count() (which already counts the filtered sheets). I'll keep iterating workbook.sheetnames and add tests covering page_range with and without sheet_names.

One quick question: should selected sheets keep their original page numbers (e.g. (2, 4) → pages 2, 3, 4, matching the PPTX backend), or be renumbered from 1? I'll go with preserving them unless you prefer otherwise. Thank you very much!

DanielNg0729 avatar Jun 17 '26 07:06 DanielNg0729

Thanks @DanielNg0729 ! I like the plan you described and I agree with keeping the original page numbers.

ceberam avatar Jun 17 '26 07:06 ceberam