Remove create table helper function
This commit is contained in:
@ -1,14 +1,16 @@
|
||||
// Add custom borders to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { BorderStyle, Document, Packer, Paragraph } from "../build";
|
||||
import { BorderStyle, Document, Packer, Paragraph, Table } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 4,
|
||||
columns: 4,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
table
|
||||
.getCell(2, 2)
|
||||
.addParagraph(new Paragraph("Hello"))
|
||||
|
@ -1,14 +1,17 @@
|
||||
// Add image to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Media, Packer, Paragraph } from "../build";
|
||||
import { Document, Media, Packer, Paragraph, Table } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 4,
|
||||
columns: 4,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
|
||||
|
||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||
|
@ -1,28 +1,29 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, VerticalAlign } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, VerticalAlign, Table } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 2,
|
||||
columns: 2,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table
|
||||
.getCell(1, 1)
|
||||
.addParagraph(new Paragraph("This text should be in the middle of the cell"))
|
||||
.setVerticalAlign(VerticalAlign.CENTER);
|
||||
|
||||
table
|
||||
.getCell(1, 0)
|
||||
.addParagraph(
|
||||
new Paragraph({
|
||||
text:
|
||||
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
);
|
||||
table.getCell(1, 0).addParagraph(
|
||||
new Paragraph({
|
||||
text:
|
||||
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
);
|
||||
|
||||
const packer = new Packer();
|
||||
|
||||
|
@ -1,15 +1,17 @@
|
||||
// Example of how you would merge cells together
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, ShadingType, WidthType } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, WidthType } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
let table = doc.createTable({
|
||||
let table = new Table({
|
||||
rows: 2,
|
||||
columns: 2,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
|
||||
table.getRow(0).mergeCells(0, 1);
|
||||
|
||||
@ -20,13 +22,16 @@ doc.addParagraph(
|
||||
}),
|
||||
);
|
||||
|
||||
table = doc.createTable({
|
||||
table = new Table({
|
||||
rows: 2,
|
||||
columns: 3,
|
||||
width: 100,
|
||||
widthUnitType: WidthType.AUTO,
|
||||
columnWidths: [1000, 1000, 1000],
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table
|
||||
.getCell(0, 0)
|
||||
.addParagraph(new Paragraph("World"))
|
||||
@ -45,7 +50,7 @@ doc.addParagraph(
|
||||
}),
|
||||
);
|
||||
|
||||
table = doc.createTable({
|
||||
table = new Table({
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
width: 7000,
|
||||
@ -57,6 +62,9 @@ table = doc.createTable({
|
||||
left: 400,
|
||||
},
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table.getCell(0, 0).addParagraph(new Paragraph("Foo"));
|
||||
table.getCell(0, 1).addParagraph(new Paragraph("v"));
|
||||
|
||||
@ -97,13 +105,15 @@ table.getRow(0).mergeCells(0, 3);
|
||||
|
||||
doc.addParagraph(new Paragraph("hi"));
|
||||
|
||||
doc.createTable({
|
||||
table = new Table({
|
||||
rows: 2,
|
||||
columns: 2,
|
||||
width: 100,
|
||||
widthUnitType: WidthType.PERCENTAGE,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
const packer = new Packer();
|
||||
|
||||
packer.toBuffer(doc).then((buffer) => {
|
||||
|
@ -1,11 +1,20 @@
|
||||
// Example of how you would create a table with float positions
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, RelativeHorizontalPosition, RelativeVerticalPosition, TableAnchorType, WidthType } from "../build";
|
||||
import {
|
||||
Document,
|
||||
Packer,
|
||||
Paragraph,
|
||||
RelativeHorizontalPosition,
|
||||
RelativeVerticalPosition,
|
||||
Table,
|
||||
TableAnchorType,
|
||||
WidthType,
|
||||
} from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 2,
|
||||
columns: 2,
|
||||
float: {
|
||||
@ -17,6 +26,8 @@ const table = doc.createTable({
|
||||
width: 4535,
|
||||
widthUnitType: WidthType.DXA,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
table.setFixedWidthLayout();
|
||||
|
||||
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
|
||||
|
@ -1,14 +1,17 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, Packer, Paragraph, Table } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 4,
|
||||
columns: 4,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
|
||||
|
||||
const packer = new Packer();
|
||||
|
@ -1,14 +1,17 @@
|
||||
// Multiple cells merging in the same table
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, Packer, Paragraph, Table } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 13,
|
||||
columns: 6,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
let row = 0;
|
||||
table.getCell(row, 0).addParagraph(new Paragraph("0,0"));
|
||||
table.getCell(row, 1).addParagraph(new Paragraph("0,1"));
|
||||
|
@ -1,14 +1,17 @@
|
||||
// Add image to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, Packer, Paragraph, Table } from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
const table = doc.createTable({
|
||||
const table = new Table({
|
||||
rows: 4,
|
||||
columns: 4,
|
||||
});
|
||||
|
||||
doc.addTable(table);
|
||||
|
||||
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
|
||||
table.getColumn(3).mergeCells(1, 2);
|
||||
// table.getCell(3, 2).addParagraph(new Paragraph("Hello"));
|
||||
|
Reference in New Issue
Block a user