EnxDev commented on code in PR #43718:
URL: https://github.com/apache/superset/pull/43718#discussion_r3903734797


##########
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:
   @msyavuz, what do you think about including `kwargs.get("startcol", 0)` in 
this offset? `EXCEL_EXPORT` forwards that option to `DataFrame.to_excel`, and 
the pivot XLSX values otherwise keep the `General` format when the sheet starts 
after column A.



##########
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:
   @msyavuz, what do you think about scoping this to `pivot_table_v2` too? 
`apply_client_processing` also handles Table charts, and stale form data can 
retain `showValuesAs`. In that case a raw XLSX value like `10` gets this format 
and displays as `1000.0%`.



-- 
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]

Reply via email to