sadpandajoe commented on code in PR #45407:
URL: https://github.com/apache/superset/pull/45407#discussion_r4320255562


##########
superset/utils/excel.py:
##########
@@ -48,12 +48,18 @@
 
 
 def _quote_formula(value: Any) -> Any:
-    """Prefix a string with a quote when it would parse as a formula."""
-    return (
-        f"'{value}"
-        if isinstance(value, str) and len(value) and value[0] in 
FORMULA_PREFIXES
-        else value
-    )
+    """Prefix a string with a quote when it would parse as a formula.
+
+    Leading whitespace is ignored when detecting a formula, because spreadsheet
+    apps still evaluate a cell whose formula prefix is preceded by spaces or
+    tabs (e.g. ``" =cmd"`` or ``"\t=cmd"``). This matches the streaming writer
+    in ``superset.utils.excel_streaming``, which the comment on
+    ``FORMULA_PREFIXES`` says both export paths agree with.
+    """
+    if not isinstance(value, str):
+        return value
+    stripped = value.lstrip()
+    return f"'{value}" if stripped and stripped[0] in FORMULA_PREFIXES else 
value

Review Comment:
   This also changes benign values: a dataset string like `"  - North"` 
(indented list-style label) used to export unchanged and will now land in the 
cell as `'  - North`, with a visible apostrophe. The XLSX path writes through 
XlsxWriter, which only treats a string as a formula when it starts with `=`, so 
a whitespace-prefixed value was already stored as a plain string cell rather 
than a live formula. Is there a case where the leading-whitespace form is 
actually evaluated in the XLSX output? If not, should this stay as it was and 
leave the whitespace handling to the CSV/streaming writers?



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