DEV Community

kanta13jp1
kanta13jp1

Posted on

Parsing XLSX/DOCX in the Browser with Pure Dart — No Server Round-Trip Needed

Parsing XLSX/DOCX in the Browser with Pure Dart — No Server Round-Trip Needed

Introduction

I'm building jibun inc., a Flutter Web + Supabase personal SaaS competing with Notion. When Notion 3.6 shipped Excel/Word import, I needed to match that feature fast.

Two constraints made it non-trivial:

  1. No dart:io on Flutter Web — all file content must come through as Uint8List.
  2. Avoiding unnecessary server calls — routing 5 MB Excel files through an Edge Function on every import is bad UX and wastes cold-start latency.

The solution: a pure Dart parser that runs entirely in the browser.

How OOXML Works

Both .xlsx and .docx are ZIP archives containing XML files — the Office Open XML (OOXML) standard. Rename any .xlsx to .zip and unzip it to see:

book.xlsx
├── xl/sharedStrings.xml   ← string dictionary
├── xl/worksheets/sheet1.xml ← cell data (index references)
└── [Content_Types].xml
Enter fullscreen mode Exit fullscreen mode

Dart's archive package handles the ZIP layer, and xml handles the XML parsing. The whole parser is a zero-Flutter-dependency class: OfficeDocumentParser.

Implementation

XLSX Parsing

The tricky parts of parsing XLSX:

1. Shared strings — string cells don't store text directly; they store an integer index into sharedStrings.xml. Cells with <c t="s"> hold indices; cells without t hold raw numbers.

2. Column address → index conversion — cells are addressed as A1, BC42, etc. Empty cells are simply absent from the XML, so you must reconstruct the full 2D grid:

int _colIndex(String ref) {
  // "A"→0, "B"→1, "Z"→25, "AA"→26
  final letters = ref.replaceAll(RegExp(r'[0-9]'), '');
  return letters.codeUnits.fold(0, (acc, c) => acc * 26 + (c - 64)) - 1;
}
Enter fullscreen mode Exit fullscreen mode

3. Namespace-agnostic element matching — use localName instead of name:

// Works regardless of whether elements are prefixed w:p or unprefixed p
doc.findAllElements('p', namespace: '*')
Enter fullscreen mode Exit fullscreen mode

DOCX Parsing

Word documents are simpler: extract paragraphs from word/document.xml:

String parseDocxToText(Uint8List bytes) {
  final archive = ZipDecoder().decodeBytes(bytes);
  final content = utf8.decode(
    archive.findFile('word/document.xml')!.content as List<int>
  );
  return XmlDocument.parse(content)
      .findAllElements('p', namespace: '*')
      .map((p) => p.findAllElements('t', namespace: '*')
          .map((t) => t.innerText)
          .join())
      .where((s) => s.isNotEmpty)
      .join('\n');
}
Enter fullscreen mode Exit fullscreen mode

Structured Task Fields (GitHub Issue Fields equivalent)

Alongside the import feature, I added priority / effort / target_date columns to the task tables. Supabase migration:

ALTER TABLE feature_requests
  ADD COLUMN priority TEXT CHECK (priority IN ('p0','p1','p2','p3')),
  ADD COLUMN effort   TEXT CHECK (effort   IN ('xs','s','m','l','xl')),
  ADD COLUMN target_date DATE;
Enter fullscreen mode Exit fullscreen mode

On the Flutter side, a shared StructuredFieldChips widget renders these fields consistently across the public feature-requests page and the admin dashboard.

Challenges

API drift between major versions — archive 4.x changed the decodeBytes return type, and xml 6.x made namespace a required parameter in some contexts. Lesson: verify the actual API against the GitHub source before writing code, and pin versions explicitly in pubspec.yaml.

file_picker on Web returns bytes, not paths — PlatformFile.bytes gives you the Uint8List directly. No temp files, no paths — pass it straight to the parser.

Shared string index vs. raw value — forgetting to check the t="s" attribute means every string cell shows as a number. The t attribute is the discriminator between string-index cells and numeric cells.

Results

  • XLSX and DOCX import now run fully in the browser — zero server calls
  • The parser is a plain Dart class with no Flutter dependency, so it's easily testable with dart test (VM tests, no widget overhead)
  • CHECK constraints in Supabase enforce valid priority/effort values at the DB layer

What's Next

AI-assisted tagging — when a spreadsheet is imported, infer priority and effort from column headers using Claude API via a Supabase Edge Function. This would turn a raw Excel task list into a structured backlog in one click.


Building in public: https://my-web-app-b67f4.web.app/

FlutterWeb #Supabase #Dart #OOXML #buildinpublic #webdev

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

This is the kind of post that saves someone an entire weekend — the OOXML format looks simple until you actually have to rebuild a grid from it. The two traps you name are exactly the ones that bite: cells with t="s" holding an index into sharedStrings.xml instead of text, and empty cells simply being absent from the XML, so you have to reconstruct the full 2D grid from A1/BC42 addresses yourself. Keeping OfficeDocumentParser a plain Dart class with no Flutter dependency is the decision that pays for itself — being able to test it with plain dart test, no widget overhead, makes the shared-strings and namespace edge cases actually verifiable. And matching the namespace-agnostic localName approach instead of fighting w:p prefixes is the right call. One question: with a 5 MB Excel file decoded through ZipDecoder on the web, does the whole parse run on the main isolate, and have you hit any UI jank on larger sheets — or is moving the parse into an isolate the next step before the AI-assisted tagging work?

Collapse
 
kanta13jp1 profile image
kanta13jp1 •

Great question—on Flutter Web specifically, Dart's compute() currently runs on the main browser event loop rather than a separate OS thread, so a large 5 MB workbook decoded all at once can still cause brief frame jank. For heavier sheets on web, the practical path is either yielding between chunked row batches (await Future.delayed(Duration.zero)) or offloading decompression/parsing into a dedicated Web Worker via JS interop. Keeping OfficeDocumentParser pure Dart keeps those boundaries easy to swap!