* 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
34 lines
974 B
TypeScript
34 lines
974 B
TypeScript
// Example of making content of section vertically aligned
|
|
|
|
import * as fs from "fs";
|
|
import { Document, Packer, Paragraph, VerticalAlignSection, TextRun, Tab } from "docx";
|
|
|
|
const doc = new Document({
|
|
sections: [
|
|
{
|
|
properties: {
|
|
verticalAlign: VerticalAlignSection.CENTER,
|
|
},
|
|
children: [
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun("Hello World"),
|
|
new TextRun({
|
|
text: "Foo Bar",
|
|
bold: true,
|
|
}),
|
|
new TextRun({
|
|
children: [new Tab(), "Github is the best"],
|
|
bold: true,
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
});
|