linexcel.insights¶
linexcel.insights ¶
Workbook context extraction and optional screenshot rendering.
WorkbookRenderError ¶
extract_workbook_context ¶
extract_workbook_context(data: bytes, filename: str = 'workbook.xlsx', *, preview_rows: int = PREVIEW_ROWS, preview_columns: int = PREVIEW_COLUMNS) -> dict[str, Any]
Extract bounded presentation context without launching Excel.
The preview preserves the first cells as they are, without guessing which row is a header. Comments and sheet layout markers complement formula lineage with the cues users usually see when opening a workbook.
Source code in src/linexcel/insights.py
detect_tables ¶
Detect Excel tables (TableObjects) and static tables on a worksheet.
Returns one dict per table with name, kind ("dynamic" or
"static"), ref, bounds (header_row, first_row, last_row,
first_col, last_col), headers and data_rows.
Dynamic tables come from ws.tables (what Excel calls a Table / List
Object). Static tables are ranges that look like a table — a header row
of text above contiguous data — detected heuristically so a workbook with
no formal tables still benefits from header/index enrichment.
Source code in src/linexcel/insights.py
find_libreoffice ¶
Locate the LibreOffice launcher, on PATH or in a standard install.
Windows and macOS installers do not put LibreOffice on PATH, so a
PATH-only lookup reports the renderer as missing on machines where it is
installed. Well-known install directories are therefore searched as well.
Source code in src/linexcel/insights.py
find_pdftoppm ¶
Locate Poppler's pdftoppm, on PATH or in a standard install.
Source code in src/linexcel/insights.py
render_workbook_screenshots ¶
render_workbook_screenshots(data: bytes, filename: str, output_dir: str | Path, *, dpi: int = 144, timeout: int = 180, per_sheet: bool = True) -> dict[str, list[Path]] | list[Path]
Render workbook sheets to PNG with LibreOffice and Poppler.
Works on Linux, macOS and Windows. LibreOffice runs headlessly; no desktop
Excel process is needed. It exports the workbook to PDF, then pdftoppm
creates one PNG per rendered page.
With per_sheet — the default — LibreOffice is asked to put each sheet on
a single page, so the result is a {sheet name: [png]} mapping keyed by
the workbook's own sheet names, and the report shows each image under the
sheet it belongs to. Sheets are not split across pages, so a long one comes
out as one tall image rather than as print pages nobody can map back.
Setting per_sheet=False returns the flat list[Path] of print pages
instead, as the page setup of the workbook lays them out.
The mapping is only returned when LibreOffice produced exactly one page per sheet. When it did not — an older build ignoring the option, a page setup that overrides it — the flat page list is returned rather than a guessed mapping, because a screenshot filed under the wrong sheet is worse than one filed under none.
Source code in src/linexcel/insights.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |