EnxDev commented on code in PR #43718:
URL: https://github.com/apache/superset/pull/43718#discussion_r3903625302
##########
superset/charts/client_processing.py:
##########
@@ -886,6 +1439,14 @@ def apply_client_processing( # noqa: C901
excel.apply_column_types(processed_df, query["coltypes"])
query["data"] = excel.df_to_excel(
processed_df,
+ # A percent mode leaves every cell a fraction. Excel can render
+ # those as percentages without turning them into text, so the
+ # workbook reads like the chart and still calculates.
+ number_format=(
+ EXCEL_PERCENT_FORMAT
+ if form_data.get("showValuesAs") in
SHOW_VALUES_AS_PERCENT_MODES
Review Comment:
Could we scope this to `viz_type == "pivot_table_v2"` as well?
`apply_client_processing` also handles Table charts, and stale form data can
retain `showValuesAs`. In that case no fraction transform runs, but an XLSX
value like `10` gets this format and displays as `1000.0%`.
##########
superset/utils/excel.py:
##########
@@ -101,6 +111,17 @@ def df_to_excel(df: pd.DataFrame, **kwargs: Any) -> Any:
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
df.to_excel(writer, **kwargs)
+ if number_format and writer.sheets:
+ worksheet = next(iter(writer.sheets.values()))
+ # The index occupies the leading columns when it is written out.
+ first_data_column = df.index.nlevels if kwargs.get("index", True)
else 0
Review Comment:
Could we include `kwargs.get("startcol", 0)` in this offset? `EXCEL_EXPORT`
is forwarded to `DataFrame.to_excel`, so with `startcol=2` the value lands in
C2 while the format starts at A; the data cell stays `General`.
--
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]