AliIbnBotir opened a new pull request, #45279: URL: https://github.com/apache/superset/pull/45279
### SUMMARY Part of SIP #45265. > **Stacked on #CHART_PR (Spreadsheet chart), which depends on #45263 and #45275.** This branch contains their commits, so until they merge, please review only the last commit, `feat(chart-data): export the Spreadsheet chart to Excel with its edits`. Backend only. "Export to Excel" on a Spreadsheet chart writes the sheet as the user sees it instead of the raw query result: - renamed headers, formulas (with cached values), cell styles, merges, column widths and frozen panes; - pivot mode's stacked header rows; - row groups as real Excel outline groups, with Subtotals and Grand Total rows. How it works: - In `QueryContextProcessor.get_data`, an XLSX request whose form data has `viz_type == "univer_sheet"` goes to the new `superset/utils/univer_excel.py` instead of `excel.df_to_excel`. Every other chart takes the existing path unchanged. - `univer_excel.py` rebuilds the same sheet the browser shows (data area, pivot headers, groups, saved edits from `univer_workbook`) and writes it with XlsxWriter, which is already a dependency. - Shared formulas are moved with `openpyxl`'s formula translator. `openpyxl` was already installed through `pandas[excel]` and is now declared directly in `pyproject.toml` (`>=3.1.5, <4`). `requirements/*.txt` are updated accordingly, no new package is installed. - It reuses the chart-data endpoint, so permissions, row limits and config apply as before. Explore sends the current form data, so unsaved edits are exported too. Dashboards, reports and alerts use the saved chart. - CSV and JSON exports still return the raw query result. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF <img width="1228" height="525" alt="05-excel-export" src="https://github.com/user-attachments/assets/3cef9c18-227a-4834-af4a-dc8d78562e48" /> _Export to Excel from the chart menu, and the downloaded .xlsx: renamed headers, header fill and the Average formulas are kept._ Before: the .xlsx contained the raw query result with the original column names and no formatting, formulas or groups. ### TESTING INSTRUCTIONS Automated: - `pytest tests/unit_tests/utils/univer_excel_test.py tests/unit_tests/common/test_query_context_processor.py` Manual (needs the chart PR): 1. Open a Spreadsheet chart in Explore, rename a header, colour the header row and add a formula row under the data. 2. Chart menu → Download → **Export to Excel**. Open the file: the renamed header, fill and formulas are there, and the formulas have values. 3. Switch to Pivot mode and export again: the stacked header rows are merged as in the browser. 4. Turn on **Group rows by dimensions** and export: Excel shows outline groups (the 1/2 buttons on the left) with Subtotals rows. 5. Export any other chart type to Excel: the output is unchanged. ### ADDITIONAL INFORMATION - [x] Has associated issue: SIP #45265 - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [x] Introduces new feature or API - [ ] Removes existing feature or API -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
