dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.

Home Page:https://docx.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tableHeader repeats row only if declared on the first row in a table

StephanBijzitter opened this issue · comments

From the documentation: https://docx.js.org/#/usage/tables?id=repeat-row

If a table is paginated on multiple pages, it is possible to repeat a row at the top of each new page by setting tableHeader to true:

const row = new TableRow({
    ...,
    tableHeader: true,
});

The wording suggests that this is what Microsoft Word describes as "repeat header rows":
image

According to #2310 the w:tblHeader property is used, which only applies when added to the first row of a table and is otherwise ignored.

When you create a table like this:

begin table
header 1 (tableHeader=true)
... lots of content rows
header 2 (tableHeader=true)
... lots of content rows
header 3 (tableHeader=true)
... lots of content rows
end table

The header 1 shows up on every page, even in between header 2 and header 3, which is technically correct as that's exactly what w:tblHeader is supposed to do, but it's definitely wrong from the perspective of the reader,

The workaround I've found is as follows:

begin table 1
header 1 (tableHeader=true)
... lots of content rows
end table 1
empty paragraph (to keep tables from collapsing into each other)
begin table 2
header 2 (tableHeader=true)
... lots of content rows
end table 2
empty paragraph (to keep tables from collapsing into each other)
begin table 3
header 3 (tableHeader=true)
... lots of content rows
end table 3

After double-checking, it turns out that the document created with Microsoft Word (where I have only created one table) is split up into multiple tables as well when performing the steps as shown in the screenshot above. Maybe this (awesome) library could do the same when detecting multiple rows with tableHeader=true, or update the documentation a little bit to include this caveat.