Add header objects and demo
This commit is contained in:
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@ -1,16 +1,9 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"clippy",
|
||||
"docx",
|
||||
"dolan",
|
||||
"miu",
|
||||
"officegen",
|
||||
"typedoc"
|
||||
],
|
||||
"cSpell.words": ["clippy", "docx", "dolan", "miu", "officegen", "typedoc"],
|
||||
"prettier.trailingComma": "all",
|
||||
"prettier.printWidth": 140,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnSave": false,
|
||||
"prettier.tabWidth": 4,
|
||||
"prettier.arrowParens": "always",
|
||||
"prettier.bracketSpacing": true,
|
||||
"prettier.bracketSpacing": true
|
||||
}
|
||||
|
12
demo/demo8.js
Normal file
12
demo/demo8.js
Normal file
@ -0,0 +1,12 @@
|
||||
const docx = require('../build');
|
||||
|
||||
var doc = new docx.File();
|
||||
|
||||
doc.createParagraph("Hello World");
|
||||
|
||||
doc.Header.createParagraph("Header text");
|
||||
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
exporter.pack('My Document');
|
||||
|
||||
console.log('Document created succesfully at project root!');
|
@ -42,6 +42,7 @@ export class Compiler {
|
||||
});
|
||||
const xmlNumbering = xml(this.formatter.format(this.file.Numbering));
|
||||
const xmlRelationships = xml(this.formatter.format(this.file.Relationships));
|
||||
const xmlHeader = xml(this.formatter.format(this.file.Header));
|
||||
|
||||
this.archive.append(xmlDocument, {
|
||||
name: "word/document.xml",
|
||||
@ -59,6 +60,10 @@ export class Compiler {
|
||||
name: "word/numbering.xml",
|
||||
});
|
||||
|
||||
this.archive.append(xmlHeader, {
|
||||
name: "word/header1.xml",
|
||||
});
|
||||
|
||||
this.archive.append(xmlRelationships, {
|
||||
name: "word/_rels/document.xml.rels",
|
||||
});
|
||||
|
@ -0,0 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IHeaderReferenceAttributes {
|
||||
type: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class HeaderReferenceAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> {
|
||||
protected xmlKeys = {
|
||||
type: "w:type",
|
||||
id: "r:id",
|
||||
};
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { HeaderReferenceAttributes } from "./header-reference-attributes";
|
||||
|
||||
export class HeaderReference extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:headerReference");
|
||||
this.root.push(
|
||||
new HeaderReferenceAttributes({
|
||||
type: "default",
|
||||
id: `rId${3}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
// http://officeopenxml.com/WPsection.php
|
||||
import { IColumnsAttributes } from "file/document/body/section-properties/columns/columns-attributes";
|
||||
import { IPageMarginAttributes } from "file/document/body/section-properties/page-margin/page-margin-attributes";
|
||||
import { IPageSizeAttributes } from "file/document/body/section-properties/page-size/page-size-attributes";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { Columns } from "./columns/columns";
|
||||
import { IColumnsAttributes } from "./columns/columns-attributes";
|
||||
import { DocumentGrid } from "./doc-grid/doc-grid";
|
||||
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
|
||||
import { HeaderReference } from "./header-reference/header-reference";
|
||||
import { PageMargin } from "./page-margin/page-margin";
|
||||
import { IPageMarginAttributes } from "./page-margin/page-margin-attributes";
|
||||
import { PageSize } from "./page-size/page-size";
|
||||
import { IPageSizeAttributes } from "./page-size/page-size-attributes";
|
||||
|
||||
export type SectionPropertiesOptions = IPageSizeAttributes & IPageMarginAttributes & IColumnsAttributes & IDocGridAttributesProperties;
|
||||
|
||||
@ -49,5 +50,6 @@ export class SectionProperties extends XmlComponent {
|
||||
);
|
||||
this.root.push(new Columns(mergedOptions.space));
|
||||
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
||||
this.root.push(new HeaderReference());
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export class File {
|
||||
}
|
||||
|
||||
public createParagraph(text?: string): Paragraph {
|
||||
return this.document.createParagraph();
|
||||
return this.document.createParagraph(text);
|
||||
}
|
||||
|
||||
public addTable(table: Table): void {
|
||||
|
@ -2,7 +2,6 @@ import * as fs from "fs";
|
||||
import * as sizeOf from "image-size";
|
||||
import * as path from "path";
|
||||
|
||||
import { Relationships } from "file/relationships/relationships";
|
||||
import { IMediaData } from "./data";
|
||||
|
||||
export class Media {
|
||||
|
@ -8,6 +8,7 @@
|
||||
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
||||
<Default Extension="xml" ContentType="application/xml" />
|
||||
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />
|
||||
<Override PartName="/word/header1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"/>
|
||||
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" />
|
||||
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
|
||||
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
|
||||
|
Reference in New Issue
Block a user