Add dynamic relationships
This commit is contained in:
@ -0,0 +1,15 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IRelationshipAttributesProperties {
|
||||
id: string;
|
||||
type: string;
|
||||
target: string;
|
||||
}
|
||||
|
||||
export class RelationshipAttributes extends XmlAttributeComponent<IRelationshipAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
id: "Id",
|
||||
type: "Type",
|
||||
target: "Target",
|
||||
};
|
||||
}
|
23
src/file/relationships/relationship/relationship.ts
Normal file
23
src/file/relationships/relationship/relationship.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { RelationshipAttributes } from "./relationship-attributes";
|
||||
|
||||
export type RelationshipType =
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"
|
||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
|
||||
|
||||
export class Relationship extends XmlComponent {
|
||||
constructor(id: string, type: RelationshipType, target: string) {
|
||||
super("Relationship");
|
||||
|
||||
this.root.push(new RelationshipAttributes({
|
||||
id,
|
||||
type,
|
||||
target,
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { RelationshipsAttributes } from "./attributes";
|
||||
import { Relationship, RelationshipType } from "./relationship/relationship";
|
||||
|
||||
export class Relationships extends XmlComponent {
|
||||
|
||||
@ -9,6 +10,18 @@ export class Relationships extends XmlComponent {
|
||||
xmlns: "http://schemas.openxmlformats.org/package/2006/relationships",
|
||||
}));
|
||||
|
||||
// this.root.push(new Created());
|
||||
this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
||||
this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
||||
}
|
||||
|
||||
public addRelationship(relationship: Relationship): void {
|
||||
this.root.push(relationship);
|
||||
}
|
||||
|
||||
public createRelationship(id: number, type: RelationshipType, target: string): Relationship {
|
||||
const relationship = new Relationship(`rId${id}`, type, target);
|
||||
this.addRelationship(relationship);
|
||||
|
||||
return relationship;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user