Skip to content

feat(excel): add toJson/fromJson &generateXFile; fix column/row sizing and cell parsing - #422

Open
mkidv wants to merge 2 commits into
justkawal:mainfrom
mkidv:feat/excel-mki
Open

mkidv wants to merge 2 commits into
justkawal:mainfrom
mkidv:feat/excel-mki

Conversation

@mkidv

@mkidv mkidv commented Aug 12, 2025

Copy link
Copy Markdown

Summary

Adds a JSON API, an XFile export helper, and fixes several parsing issues (column/row sizing and cell types). Strengthens cell parsing (formulas/inline strings/num formats) and extends the test suite.

Motivation

  • Convert workbooks to/from a JSON view for storage, diffing, or APIs.
  • Provide a first-class way to get an XFile (Flutter/web/desktop) without manual plumbing.
  • Address sizing inconsistencies and parsing edge cases across Excel / Google Sheets / LibreOffice.

What’s changed

  • Added
    • Excel.toJson() / Excel.fromJson(Map) and toString()jsonEncode(toJson()).
    • Excel.generateXFile({fileName}) → returns an XFile with the correct MIME & name.
    • Browser saving helper now also exposes generateXFile.
  • Fixed
    • Column widths & row heights parsing: defaults + per-col/per-row (<sheetFormatPr>, <col width>, <row ht>).
    • Cell parsing robustness:
      • Formula-first handling (<f> preferred over <v> when present).
      • Safe sharedStrings lookup (bounds checks).
      • Full t="inlineStr" support.
      • Bounds checks for numFmtId/style indices with sensible fallbacks.

API snippets

// JSON round-trip
final json = excel.toJson();
final excel2 = Excel.fromJson(json);

// XFile generation (Flutter/web/desktop)
final xf = excel.generateXFile(fileName: 'report.xlsx');
// -> XFile(name: report.xlsx, mime: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)

Notes on JSON format

  • Dates/DateTimes use ISO-8601 UTC strings with milliseconds:
    • DateCellValue → YYYY-MM-DDT00:00:00.000Z
    • DateTimeCellValue → YYYY-MM-DDTHH:mm:ss.SSSZ
    • Times are HH:mm:ss[.SSS].
  • Formulas are strings starting with =….
  • Numeric/bool types stay typed on re-import; text remains text.

Tests

  • JSON view stable across encode/decode.
  • inlineStr cells read correctly.
  • XFile generation returns correct name + MIME.

Backward compatibility

  • No breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant