Fix: separate vertical alignment enums for ITableCellOptions and ISectionPropertiesOptions (#3079)
* 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
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlignTable, TextDirection } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -13,11 +13,11 @@ const doc = new Document({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||
@ -45,7 +45,7 @@ const doc = new Document({
|
||||
text: "This text should be in the middle of the cell",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -53,7 +53,7 @@ const doc = new Document({
|
||||
text: "Text above should be vertical from bottom to top",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -61,7 +61,7 @@ const doc = new Document({
|
||||
text: "Text above should be vertical from top to bottom",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Example of making content of section vertically aligned
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, VerticalAlign, TextRun, Tab } from "docx";
|
||||
import { Document, Packer, Paragraph, VerticalAlignSection, TextRun, Tab } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
properties: {
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignSection.CENTER,
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
|
@ -12,7 +12,7 @@ import {
|
||||
TableCell,
|
||||
TableRow,
|
||||
TextDirection,
|
||||
VerticalAlign,
|
||||
VerticalAlignTable,
|
||||
} from "docx";
|
||||
|
||||
const table = new Table({
|
||||
@ -102,11 +102,11 @@ const noBorderTable = new Table({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||
@ -134,7 +134,7 @@ const noBorderTable = new Table({
|
||||
text: "This text should be in the middle of the cell",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -142,7 +142,7 @@ const noBorderTable = new Table({
|
||||
text: "Text above should be vertical from bottom to top",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -150,7 +150,7 @@ const noBorderTable = new Table({
|
||||
text: "Text above should be vertical from top to bottom",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The demo on the README.md
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "docx";
|
||||
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlignTable } from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
@ -13,6 +13,7 @@ const table = new Table({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||
type: "jpg",
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
@ -21,7 +22,7 @@ const table = new Table({
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -30,7 +31,7 @@ const table = new Table({
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -50,6 +51,7 @@ const table = new Table({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||
type: "jpg",
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
@ -77,6 +79,7 @@ const doc = new Document({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||
type: "gif",
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
Table,
|
||||
TableCell,
|
||||
TableRow,
|
||||
VerticalAlign,
|
||||
VerticalAlignTable,
|
||||
TextDirection,
|
||||
TextRun,
|
||||
WidthType,
|
||||
@ -101,17 +101,17 @@ const generateRows = (prices: StockPrice[]): TableRow[] =>
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph(date.toString())],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph(ticker)],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph(price.toString())],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
}),
|
||||
],
|
||||
@ -143,7 +143,7 @@ const doc = new Document({
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
@ -159,7 +159,7 @@ const doc = new Document({
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
@ -175,7 +175,7 @@ const doc = new Document({
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
}),
|
||||
],
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
TableRow,
|
||||
TextDirection,
|
||||
TextRun,
|
||||
VerticalAlign,
|
||||
VerticalAlignTable,
|
||||
} from "docx";
|
||||
|
||||
patchDocument({
|
||||
@ -105,11 +105,11 @@ patchDocument({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||
@ -137,7 +137,7 @@ patchDocument({
|
||||
text: "This text should be in the middle of the cell",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -145,7 +145,7 @@ patchDocument({
|
||||
text: "Text above should be vertical from bottom to top",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -153,7 +153,7 @@ patchDocument({
|
||||
text: "Text above should be vertical from top to bottom",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
TableRow,
|
||||
TextDirection,
|
||||
TextRun,
|
||||
VerticalAlign,
|
||||
VerticalAlignTable,
|
||||
} from "docx";
|
||||
|
||||
patchDocument({
|
||||
@ -105,11 +105,11 @@ patchDocument({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||
@ -137,7 +137,7 @@ patchDocument({
|
||||
text: "This text should be in the middle of the cell",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -145,7 +145,7 @@ patchDocument({
|
||||
text: "Text above should be vertical from bottom to top",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
@ -153,7 +153,7 @@ patchDocument({
|
||||
text: "Text above should be vertical from top to bottom",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
verticalAlign: VerticalAlignTable.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
Reference in New Issue
Block a user