From e5537b726e954e1112cc89720533a172f608b292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D1=80=D0=BD=D0=B0=D1=82=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Tue, 2 Jun 2026 09:06:22 +0300 Subject: [PATCH] Preserve empty QWord tables in DOCX export --- src/io/wordOffice.test.ts | 27 +++++++++++++++++++++++++++ src/io/wordOffice.ts | 6 +----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/io/wordOffice.test.ts b/src/io/wordOffice.test.ts index f8eb518..5e9a703 100644 --- a/src/io/wordOffice.test.ts +++ b/src/io/wordOffice.test.ts @@ -349,6 +349,33 @@ describe("wordOffice helpers", () => { ]); }); + it("сохраняет пустые ячейки и строки таблицы для DOCX", async () => { + const html = ` + + + +

Итог
 
+ `; + const blocks = htmlToWordBlocks(html); + const blob = await exportDocxBlob("Пустая таблица.docx", html); + const zip = await JSZip.loadAsync(await blob.arrayBuffer()); + const documentXml = (await zip.file("word/document.xml")?.async("string")) ?? ""; + + expect(blocks).toEqual([ + { + type: "table", + rows: [ + ["", "", "Итог"], + ["", "", ""] + ] + } + ]); + expect(documentXml).toContain(""); + expect(documentXml.match(//g)).toHaveLength(2); + expect(documentXml.match(//g)).toHaveLength(6); + expect(documentXml).toContain("Итог"); + }); + it("сохраняет размер шрифта из HTML inline-стилей для DOCX", () => { const blocks = htmlToWordBlocks(`

Normal Large Pixel size

diff --git a/src/io/wordOffice.ts b/src/io/wordOffice.ts index db9b92e..560b2e1 100644 --- a/src/io/wordOffice.ts +++ b/src/io/wordOffice.ts @@ -647,11 +647,7 @@ function parseHtmlFragment(html: string) { function tableRows(table: Element) { return Array.from(table.querySelectorAll("tr")) - .map((row) => - Array.from(row.querySelectorAll("th,td")) - .map(elementText) - .filter((cell) => cell.length > 0) - ) + .map((row) => Array.from(row.querySelectorAll("th,td")).map(elementText)) .filter((row) => row.length > 0); }