codeant-ai-for-open-source[bot] commented on code in PR #42601:
URL: https://github.com/apache/superset/pull/42601#discussion_r3681028110


##########
superset-frontend/src/utils/downloadAsPivotExcel.ts:
##########
@@ -17,12 +17,47 @@
  * under the License.
  */
 import { utils, writeFile } from 'xlsx';
+import type { WorkSheet } from 'xlsx';
+
+// `raw: true` (used below) keeps every table cell as text, so ordinary
+// numbers lose their native Excel numeric type along with the
+// locale-formatted ones. A cell's text is only restored to a real number
+// when it round-trips losslessly through Number() (e.g. "42" or "-3.5"):
+// that guarantees it's a plain, unambiguous number under any locale, so
+// restoring it can't reintroduce the misparsing raw: true guards against.
+// Anything that doesn't round-trip (grouped thousands, percent suffixes,
+// trailing zero padding, other D3_FORMAT output, etc.) stays as text,
+// exactly as rendered.
+function restoreUnambiguousNumbers(sheet: WorkSheet): void {
+  Object.keys(sheet).forEach(cellRef => {
+    if (cellRef.startsWith('!')) {
+      return;
+    }
+    const cell = sheet[cellRef];
+    if (!cell || cell.t !== 's' || typeof cell.v !== 'string') {
+      return;
+    }
+    const value = Number(cell.v);
+    if (cell.v !== '' && Number.isFinite(value) && String(value) === cell.v) {
+      cell.t = 'n';
+      cell.v = value;
+    }
+  });
+}
 
 export default function exportPivotExcel(
   tableSelector: string,
   fileName: string,
 ) {
   const table = document.querySelector(tableSelector);
-  const workbook = utils.table_to_book(table);
+  // `raw: true` keeps every cell as the literal text rendered in the DOM.
+  // Without it, SheetJS tries to infer numbers/dates from the displayed
+  // string, which mangles values that were formatted using a non-US
+  // D3_FORMAT (e.g. "1.234,56" gets misread as a date or truncated number).
+  const workbook = utils.table_to_book(table, { raw: true });

Review Comment:
   **Suggestion:** Passing `raw: true` applies the text-only parsing policy to 
the entire pivot table, including date dimension headers and other cells that 
previously became native Excel dates or numbers through SheetJS inference. As a 
result, exports containing date labels such as `2024-01-01` now contain text 
instead of usable Excel date cells. Preserve the locale-formatted metric values 
without disabling type handling for unrelated headers and dimensions. [api 
mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Pivot date headers export as text, not Excel dates.
   - ⚠️ Excel date sorting and formulas lose native date semantics.
   - ⚠️ Dimension values lose SheetJS numeric/date type inference.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a16189d9be3443649ad65c0cd858e178&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a16189d9be3443649ad65c0cd858e178&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/utils/downloadAsPivotExcel.ts
   **Line:** 57:57
   **Comment:**
        *Api Mismatch: Passing `raw: true` applies the text-only parsing policy 
to the entire pivot table, including date dimension headers and other cells 
that previously became native Excel dates or numbers through SheetJS inference. 
As a result, exports containing date labels such as `2024-01-01` now contain 
text instead of usable Excel date cells. Preserve the locale-formatted metric 
values without disabling type handling for unrelated headers and dimensions.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42601&comment_hash=37d605516ecc1c271d2b14871eb788a3bc8c2231ed445647eb42ae641ecf0e71&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42601&comment_hash=37d605516ecc1c271d2b14871eb788a3bc8c2231ed445647eb42ae641ecf0e71&reaction=dislike'>👎</a>



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