Files
edentext/tests/zz-dump.test.ts
T
Steffen Becker eda134f162 feat: a formula cell prints its result in its own number format
The Formula dialog gains the number format Word's has: whole numbers, two
decimals, grouped thousands and the two percentages beside the general
one.

ODF keeps it on the cell *style* as a reference to a data style — odf-kit
shares one cell style across every cell, so a formatted cell gets a copy
of it — and LibreOffice writes both back unchanged. Word keeps it on the
field as its \# switch; LibreOffice's DOCX filter neither reads nor writes
that switch, so that leg holds through our own round trip.
2026-08-15 10:53:30 +02:00

18 lines
958 B
TypeScript

import { it } from 'vitest';
import { unzipSync, strFromU8 } from 'fflate';
import { buildOdt } from '../src/lib/export/odt';
type N = any;
const cell = (t: string, formula?: string): N => ({ type: 'tableCell', attrs: { colspan: 1, rowspan: 1, colwidth: null, ...(formula ? { formula } : {}) }, content: [{ type: 'paragraph', content: [{ type: 'text', text: t }] }] });
const doc: N = { type: 'doc', content: [
{ type: 'table', content: [
{ type: 'tableRow', content: [cell('2'), cell('3')] },
{ type: 'tableRow', content: [cell('5', 'SUM(ABOVE)'), cell('x')] },
] },
] };
it('dumps', async () => {
const bytes = await buildOdt(doc, { top: 2, bottom: 2, left: 2, right: 2 }, 'portrait');
const xml = strFromU8(unzipSync(bytes)['content.xml']);
console.log(xml.match(/<style:style[^>]*family="table-cell"[\s\S]*?<\/style:style>/g)?.join('\n'));
console.log(xml.slice(xml.indexOf('<table:table '), xml.indexOf('</table:table>') + 14));
});