Skip to content

[WC-3334] Fix DG2 export type bugs#2182

Open
samuelreichert wants to merge 10 commits intomainfrom
fix/datagrid-export-type-bugs
Open

[WC-3334] Fix DG2 export type bugs#2182
samuelreichert wants to merge 10 commits intomainfrom
fix/datagrid-export-type-bugs

Conversation

@samuelreichert
Copy link
Copy Markdown
Contributor

Pull request type

Refactoring (e.g. file rename, variable rename, etc.)
Bug fix (non-breaking change which fixes an issue)

Description

Fix multiple data export bugs in DataGrid2's Excel export feature (WC-3334).

Problems

  1. customContent columns ignore exportType — exportValue always exports as text regardless of exportType setting, making numeric values unusable for calculations in Excel
  2. Date exports leak time components — Date-only formats (e.g., dd-MMM-yyyy) carry a hidden time component in the cell value, affecting sorting and calculations
  3. Boolean exports show TRUE/FALSE — Excel boolean cells always render as TRUE/FALSE regardless of the w field; DataGrid2 displays Yes/No in the UI
  4. Long numbers lose precision — Big.toNumber() loses precision for values >15 significant digits, causing scientific notation in Excel

Changes

  • Extracted cell-creation logic from DSExportRequest.ts into standalone cell-readers.ts module (pure functions, zero behavior change)
  • customContent reader now branches on exportType: parses to Number() for "number", new Date() for "date", with graceful string
    fallback on parse failure
  • Added hasTimeComponent(format) / stripTime(date) helpers — when format has no h/s tokens, date values are normalized to midnight UTC
  • excelBoolean now returns { t: "s", v: "Yes" | "No" } instead of { t: "b" } to match grid display
  • Big values with >15 significant digits export as strings via toFixed() to preserve all digits
  • 28 new unit tests covering all reader paths, edge cases, and fallback behavior

@samuelreichert samuelreichert marked this pull request as ready for review April 20, 2026 14:06
@samuelreichert samuelreichert requested a review from a team as a code owner April 20, 2026 14:06
@samuelreichert samuelreichert force-pushed the fix/datagrid-export-type-bugs branch 2 times, most recently from b804adb to 05d8784 Compare April 24, 2026 13:57
@samuelreichert samuelreichert force-pushed the fix/datagrid-export-type-bugs branch from 05d8784 to bc6c7a0 Compare April 30, 2026 07:52
Comment on lines +6 to +16
export interface ExcelCell {
/** Cell type: 's' = string, 'n' = number, 'd' = date */
t: "s" | "n" | "d";
/** Underlying value */
v: string | number | Date;
/** Optional Excel number/date format, e.g. "yyyy-mm-dd" or "$0.00" */
z?: string;
/** Optional pre-formatted display text */
w?: string;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use "proper" names? (e.g. type, value, format?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if we want to keep it SheetJS compatible: https://docs.sheetjs.com/docs/csf/cell

}

function hasTimeComponent(format: string): boolean {
return /[hs]/i.test(format);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which format schema we use in number/date cases? Is there ISO spec or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The z property follows ECMA-376 / OOXML number format strings, the same syntax Excel uses natively.
SheetJS reads them directly and applies them in the workbook.

Dates: yyyy, mm, dd, mmm, h, s tokens
e.g. "yyyy-mm-dd", "dd-mmm-yyyy hh:mm:ss"

Numbers: #, 0, ,, . tokens
e.g. "#,##0.00", "$0.00"

There's no ISO spec here; it's the Excel format code syntax defined in ECMA-376 Part 1, §18.8.31.

The hasTimeComponent regex /[hs]/i keys off h (hours) and s (seconds) from that same token set to decide whether to strip the time part before writing the date cell.

@samuelreichert samuelreichert requested a review from iobuhov May 1, 2026 12:36
samuelreichert and others added 10 commits May 1, 2026 14:36
Documents current behavior of attribute, dynamicText, and customContent
readers before bug-fix changes are applied.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Remove "b" from ExcelCell.t union and boolean from ExcelCell.v
since excelBoolean now returns string cells. Fix misleading test
name for undefined dynamicText case.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@samuelreichert samuelreichert force-pushed the fix/datagrid-export-type-bugs branch from 0a76230 to 4e940c2 Compare May 1, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants