* fix: separate vertical alignment enums for table and section properties - Introduced `VerticalAlignTable` for table-cell vertical alignment with valid values: `top`, `center`, and `bottom`. - Added `VerticalAlignSection` for section properties, extending `VerticalAlignTable` with an additional value `both`. - Marked the original `VerticalAlign` as deprecated for backward compatibility, directing users to the new enums. - Updated type definitions for better clarity on valid vertical alignments. * refactor: update vertical alignment imports and types for section and table properties - Renamed `VerticalAlign` to `VerticalAlignSection` in section properties and `VerticalAlignTable` in table-cell properties for clarity. - Updated type definitions to reflect the new enum names, ensuring better organization and understanding of vertical alignment options. - Adjusted related test cases to utilize the new imports and types. * refactor: update demos to use new enums for table and section properties for vertical alignment
98 lines
3.2 KiB
TypeScript
98 lines
3.2 KiB
TypeScript
// The demo on the README.md
|
|
|
|
import * as fs from "fs";
|
|
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlignTable } from "docx";
|
|
|
|
const table = new Table({
|
|
rows: [
|
|
new TableRow({
|
|
children: [
|
|
new TableCell({
|
|
children: [
|
|
new Paragraph({
|
|
children: [
|
|
new ImageRun({
|
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
|
type: "jpg",
|
|
transformation: {
|
|
width: 100,
|
|
height: 100,
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
verticalAlign: VerticalAlignTable.CENTER,
|
|
}),
|
|
new TableCell({
|
|
children: [
|
|
new Paragraph({
|
|
text: "Hello",
|
|
heading: HeadingLevel.HEADING_1,
|
|
}),
|
|
],
|
|
verticalAlign: VerticalAlignTable.CENTER,
|
|
}),
|
|
],
|
|
}),
|
|
new TableRow({
|
|
children: [
|
|
new TableCell({
|
|
children: [
|
|
new Paragraph({
|
|
text: "World",
|
|
heading: HeadingLevel.HEADING_1,
|
|
}),
|
|
],
|
|
}),
|
|
new TableCell({
|
|
children: [
|
|
new Paragraph({
|
|
children: [
|
|
new ImageRun({
|
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
|
type: "jpg",
|
|
transformation: {
|
|
width: 100,
|
|
height: 100,
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
});
|
|
|
|
const doc = new Document({
|
|
sections: [
|
|
{
|
|
children: [
|
|
new Paragraph({
|
|
text: "Hello World",
|
|
heading: HeadingLevel.HEADING_1,
|
|
}),
|
|
table,
|
|
new Paragraph({
|
|
children: [
|
|
new ImageRun({
|
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
|
type: "gif",
|
|
transformation: {
|
|
width: 100,
|
|
height: 100,
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
});
|