I’m generating a .docx file using Node.js. In my header, I have a table that contains one row and two cells. The table spans the full width, and I’m trying to set the width of the cells as follows:
- The left cell, which contains an image, should be as wide as the
image. - The right cell, which contains text, should take up the remaining
width of the row (100% of the row width minus the width of the
image).
As per the documentation, I’m using the width property to define both the table’s width and the individual cell widths, but I can’t get it to work.
I also tried setting, as in the following example, the total table width to 100% and the two cells to 20% and 80%, respectively, but they still remain 50% wide each.
const headerImage = new ImageRun({
type: 'png',
data: fs.readFileSync("./public/assets/images/test-image.png"),
transformation: {
width: 120,
height: 120,
},
});
const heading = new Table({
width: {
size: 100,
type: WidthType.PERCENTAGE,
},
rows: [
new TableRow({
children: [
new TableCell({
width: {
size: 20,
type: WidthType.PERCENTAGE
},
verticalAlign: "center",
children: [
new Paragraph({
children: [
headerImage
]
})
],
}),
new TableCell({
width: {
size: 80,
type: WidthType.PERCENTAGE
},
verticalAlign: "center",
children: [
new Paragraph({
alignment: "center",
children: [
new TextRun({
text: "Text1",
bold: true,
size: "30pt",
}),
new TextRun({
text: "Text2",
italics: true,
bold: true,
size: "10pt",
break: 1
}),
new TextRun({
text: "Text3",
size: "10pt",
break: 1
}),
new TextRun({
text: "TEXT4 ",
size: "10pt",
break: 1
}),
new TextRun({
text: "Text5",
underline: {},
color: "0000FF",
})
]
}),
],
}),
],
}),
],
});