@docx4j/core-ts 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +410 -10
- package/dist/model/content/Body.d.mts +109 -4
- package/dist/model/content/Body.mjs +300 -29
- package/dist/model/content/Comment.d.mts +78 -0
- package/dist/model/content/Comment.mjs +429 -0
- package/dist/model/content/ContentControl.d.mts +173 -0
- package/dist/model/content/ContentControl.mjs +638 -0
- package/dist/model/content/Font.d.mts +48 -8
- package/dist/model/content/Font.mjs +55 -13
- package/dist/model/content/InlinePicture.d.mts +103 -0
- package/dist/model/content/InlinePicture.mjs +361 -0
- package/dist/model/content/List.d.mts +253 -0
- package/dist/model/content/List.mjs +778 -0
- package/dist/model/content/Paragraph.d.mts +213 -16
- package/dist/model/content/Paragraph.mjs +611 -57
- package/dist/model/content/Range.d.mts +48 -4
- package/dist/model/content/Range.mjs +161 -4
- package/dist/model/content/Table.d.mts +130 -0
- package/dist/model/content/Table.mjs +429 -0
- package/dist/model/content/TrackedChange.d.mts +96 -0
- package/dist/model/content/TrackedChange.mjs +352 -0
- package/dist/model/content/comments.d.mts +122 -0
- package/dist/model/content/comments.mjs +248 -0
- package/dist/model/content/index.d.mts +13 -3
- package/dist/model/content/index.mjs +15 -3
- package/dist/model/content/ooxml.d.mts +17 -0
- package/dist/model/content/ooxml.mjs +214 -0
- package/dist/model/content/styles.d.mts +21 -0
- package/dist/model/content/styles.mjs +86 -0
- package/dist/model/content/tracking.d.mts +104 -0
- package/dist/model/content/tracking.mjs +313 -0
- package/dist/model/content/tree.d.mts +56 -9
- package/dist/model/content/tree.mjs +104 -31
- package/dist/model/customxml/CustomXmlPart.d.mts +158 -0
- package/dist/model/customxml/CustomXmlPart.mjs +415 -0
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +68 -0
- package/dist/model/customxml/CustomXmlPartCollection.mjs +183 -0
- package/dist/model/customxml/XmlMapping.d.mts +46 -0
- package/dist/model/customxml/XmlMapping.mjs +98 -0
- package/dist/model/customxml/bindings.d.mts +41 -0
- package/dist/model/customxml/bindings.mjs +230 -0
- package/dist/model/customxml/index.d.mts +7 -0
- package/dist/model/customxml/index.mjs +9 -0
- package/dist/model/customxml/insert.d.mts +20 -0
- package/dist/model/customxml/insert.mjs +22 -0
- package/dist/model/customxml/kinds.d.mts +103 -0
- package/dist/model/customxml/kinds.mjs +267 -0
- package/dist/model/customxml/xpath.d.mts +52 -0
- package/dist/model/customxml/xpath.mjs +205 -0
- package/dist/model/fonts/CJKToEnglish.d.mts +2 -0
- package/dist/model/fonts/CJKToEnglish.mjs +16 -0
- package/dist/model/fonts/FontFallback.d.mts +58 -0
- package/dist/model/fonts/FontFallback.mjs +219 -0
- package/dist/model/fonts/IdentityPlusMapper.d.mts +7 -0
- package/dist/model/fonts/IdentityPlusMapper.mjs +19 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.d.mts +7 -0
- package/dist/model/fonts/LanguageTagToScriptMapping.mjs +67 -0
- package/dist/model/fonts/Mapper.d.mts +190 -0
- package/dist/model/fonts/Mapper.mjs +481 -0
- package/dist/model/fonts/PhysicalFont.d.mts +34 -0
- package/dist/model/fonts/PhysicalFont.mjs +62 -0
- package/dist/model/fonts/RunFontSelector.d.mts +194 -0
- package/dist/model/fonts/RunFontSelector.mjs +441 -0
- package/dist/model/fonts/ThemeFonts.d.mts +17 -0
- package/dist/model/fonts/ThemeFonts.mjs +76 -0
- package/dist/model/fonts/defaultTheme.d.mts +37 -0
- package/dist/model/fonts/defaultTheme.mjs +57 -0
- package/dist/model/fonts/families.generated.d.mts +11 -0
- package/dist/model/fonts/families.generated.mjs +17 -0
- package/dist/model/fonts/fontsInUse.d.mts +39 -0
- package/dist/model/fonts/fontsInUse.mjs +183 -0
- package/dist/model/fonts/index.d.mts +14 -0
- package/dist/model/fonts/index.mjs +29 -0
- package/dist/model/fonts/lookup.d.mts +5 -0
- package/dist/model/fonts/lookup.mjs +12 -0
- package/dist/model/fonts/registry.d.mts +31 -0
- package/dist/model/fonts/registry.mjs +103 -0
- package/dist/model/fonts/scripts.d.mts +2 -0
- package/dist/model/fonts/scripts.mjs +78 -0
- package/dist/model/fonts/substitutions.generated.d.mts +30 -0
- package/dist/model/fonts/substitutions.generated.mjs +12 -0
- package/dist/model/fonts/themes.generated.d.mts +6 -0
- package/dist/model/fonts/themes.generated.mjs +11 -0
- package/dist/model/index.d.mts +5 -0
- package/dist/model/index.mjs +13 -1
- package/dist/model/listnumbering/Emulator.d.mts +187 -0
- package/dist/model/listnumbering/Emulator.mjs +332 -0
- package/dist/model/listnumbering/definitions.d.mts +251 -0
- package/dist/model/listnumbering/definitions.mjs +571 -0
- package/dist/model/listnumbering/formats.d.mts +25 -0
- package/dist/model/listnumbering/formats.mjs +320 -0
- package/dist/model/listnumbering/index.d.mts +4 -0
- package/dist/model/listnumbering/index.mjs +15 -0
- package/dist/model/listnumbering/state.d.mts +97 -0
- package/dist/model/listnumbering/state.mjs +179 -0
- package/dist/model/properties/PropertyResolver.d.mts +216 -0
- package/dist/model/properties/PropertyResolver.mjs +524 -0
- package/dist/model/properties/catalogue.d.mts +179 -0
- package/dist/model/properties/catalogue.mjs +860 -0
- package/dist/model/properties/index.d.mts +4 -0
- package/dist/model/properties/index.mjs +9 -0
- package/dist/model/properties/log.d.mts +7 -0
- package/dist/model/properties/log.mjs +25 -0
- package/dist/model/properties/styleUtil.d.mts +112 -0
- package/dist/model/properties/styleUtil.mjs +359 -0
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.mjs +12 -0
- package/dist/office-js/document.d.mts +111 -0
- package/dist/office-js/document.mjs +267 -0
- package/dist/office-js/enums.d.mts +187 -0
- package/dist/office-js/enums.mjs +176 -0
- package/dist/office-js/errors.d.mts +29 -0
- package/dist/office-js/errors.mjs +39 -0
- package/dist/office-js/extras.d.mts +5 -0
- package/dist/office-js/extras.mjs +29 -0
- package/dist/office-js/fragment.d.mts +10 -0
- package/dist/office-js/fragment.mjs +23 -0
- package/dist/office-js/index.d.mts +183 -0
- package/dist/office-js/index.mjs +54 -0
- package/dist/office-js/proxy.d.mts +72 -0
- package/dist/office-js/proxy.mjs +279 -0
- package/dist/office-js/run.d.mts +32 -0
- package/dist/office-js/run.mjs +66 -0
- package/dist/office-js/supported.d.mts +7 -0
- package/dist/office-js/supported.generated.d.mts +1 -0
- package/dist/office-js/supported.generated.mjs +235 -0
- package/dist/office-js/supported.mjs +53 -0
- package/dist/office-js/toApiScript.d.mts +25 -0
- package/dist/office-js/toApiScript.mjs +394 -0
- package/dist/opc/ContentTypes.d.mts +1 -0
- package/dist/opc/ContentTypes.mjs +1 -0
- package/dist/opc/DirectoryPartStore.d.mts +47 -0
- package/dist/opc/DirectoryPartStore.mjs +123 -0
- package/dist/opc/exceptions.d.mts +30 -0
- package/dist/opc/exceptions.mjs +38 -0
- package/dist/opc/index.d.mts +1 -1
- package/dist/opc/index.mjs +1 -1
- package/dist/packages/OpcPackage.d.mts +19 -1
- package/dist/packages/OpcPackage.mjs +29 -0
- package/dist/packages/PresentationMLPackage.d.mts +71 -1
- package/dist/packages/PresentationMLPackage.mjs +179 -0
- package/dist/packages/SpreadsheetMLPackage.d.mts +30 -1
- package/dist/packages/SpreadsheetMLPackage.mjs +78 -0
- package/dist/packages/WordprocessingMLPackage.d.mts +124 -2
- package/dist/packages/WordprocessingMLPackage.mjs +309 -2
- package/dist/packages/index.d.mts +1 -1
- package/dist/packages/index.mjs +1 -1
- package/dist/parts/DefaultXmlPart.d.mts +18 -0
- package/dist/parts/DefaultXmlPart.mjs +34 -5
- package/dist/parts/PartRegistry.mjs +1 -0
- package/dist/parts/XmlPart.d.mts +33 -0
- package/dist/parts/XmlPart.mjs +105 -2
- package/dist/parts/pml/defaults.d.mts +6 -0
- package/dist/parts/pml/defaults.mjs +53 -0
- package/dist/parts/pml/index.d.mts +66 -3
- package/dist/parts/pml/index.mjs +206 -7
- package/dist/parts/pml/placeholders.d.mts +71 -0
- package/dist/parts/pml/placeholders.mjs +141 -0
- package/dist/parts/sml/index.d.mts +19 -1
- package/dist/parts/sml/index.mjs +60 -1
- package/dist/parts/wml/comments.d.mts +1 -0
- package/dist/parts/wml/comments.mjs +179 -0
- package/dist/parts/wml/defaultNumbering.d.mts +1 -0
- package/dist/parts/wml/defaultNumbering.mjs +216 -0
- package/dist/parts/wml/index.d.mts +121 -0
- package/dist/parts/wml/index.mjs +291 -0
- package/dist/xml/dom.mjs +1 -2
- package/package.json +25 -4
package/dist/opc/exceptions.mjs
CHANGED
|
@@ -13,6 +13,44 @@ export class InvalidFormatException extends Docx4JException {
|
|
|
13
13
|
this.name = 'InvalidFormatException';
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* docx4j CyclicStylesException: a style's `w:basedOn` chain comes back to a style it already
|
|
18
|
+
* holds, or goes deeper than docx4j's limit of 32. Thrown only when
|
|
19
|
+
* `throwOnCyclicStyles(true)` is set (docx4j's
|
|
20
|
+
* `docx4j.openpackaging.exceptions.CyclicStylesException.throw` property, false by default);
|
|
21
|
+
* otherwise the walk stops where the cycle was found and resolution uses as much of the
|
|
22
|
+
* hierarchy as it has.
|
|
23
|
+
*/
|
|
24
|
+
export class CyclicStylesException extends Docx4JException {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'CyclicStylesException';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Thrown by a synchronous read that needs the property resolver of a package which has not
|
|
32
|
+
* built one yet. Building it unmarshals the styles part, which cannot be done synchronously.
|
|
33
|
+
*/
|
|
34
|
+
export class PropertyResolverNotCreatedException extends Docx4JException {
|
|
35
|
+
constructor(what = 'Effective formatting') {
|
|
36
|
+
super(`${what} needs the package's PropertyResolver; await getPropertyResolver() (or getBody()) first, or read direct formatting with { direct: true }`);
|
|
37
|
+
this.name = 'PropertyResolverNotCreatedException';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** pptx4j Pptx4jException: a presentation's own structure (the slide list, a missing master). */
|
|
41
|
+
export class Pptx4jException extends Docx4JException {
|
|
42
|
+
constructor(message, options) {
|
|
43
|
+
super(message, options);
|
|
44
|
+
this.name = 'Pptx4jException';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** xlsx4j Xlsx4jException: a workbook's own structure (the sheet list). */
|
|
48
|
+
export class Xlsx4jException extends Docx4JException {
|
|
49
|
+
constructor(message, options) {
|
|
50
|
+
super(message, options);
|
|
51
|
+
this.name = 'Xlsx4jException';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
16
54
|
/** docx4j PartUnrecognisedException: no part class for a content type (the registry falls back before this is thrown). */
|
|
17
55
|
export class PartUnrecognisedException extends Docx4JException {
|
|
18
56
|
constructor(message) {
|
package/dist/opc/index.d.mts
CHANGED
|
@@ -8,5 +8,5 @@ export { loadPackage, type LoadOptions } from './Load.mjs';
|
|
|
8
8
|
export { savePackage } from './Save.mjs';
|
|
9
9
|
export { mcePreprocess, createMcePreprocessor, resolveAlternateContent, MCE_NS, type McePreprocessOptions } from './mce/preprocessor.mjs';
|
|
10
10
|
export { UNDERSTOOD_NAMESPACES } from './mce/understood.mjs';
|
|
11
|
-
export { Docx4JException, InvalidFormatException, PartUnrecognisedException } from './exceptions.mjs';
|
|
11
|
+
export { Docx4JException, InvalidFormatException, PartUnrecognisedException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
|
|
12
12
|
export { parseXml, serializeXml, serializeXmlPart, createDocument, encodeText, decodeXmlText, stripXmlDeclaration, base64Encode, base64Decode, childElements, XML_DECLARATION } from '../xml/dom.mjs';
|
package/dist/opc/index.mjs
CHANGED
|
@@ -9,5 +9,5 @@ export { loadPackage } from './Load.mjs';
|
|
|
9
9
|
export { savePackage } from './Save.mjs';
|
|
10
10
|
export { mcePreprocess, createMcePreprocessor, resolveAlternateContent, MCE_NS } from './mce/preprocessor.mjs';
|
|
11
11
|
export { UNDERSTOOD_NAMESPACES } from './mce/understood.mjs';
|
|
12
|
-
export { Docx4JException, InvalidFormatException, PartUnrecognisedException } from './exceptions.mjs';
|
|
12
|
+
export { Docx4JException, InvalidFormatException, PartUnrecognisedException, CyclicStylesException, PropertyResolverNotCreatedException } from './exceptions.mjs';
|
|
13
13
|
export { parseXml, serializeXml, serializeXmlPart, createDocument, encodeText, decodeXmlText, stripXmlDeclaration, base64Encode, base64Decode, childElements, XML_DECLARATION } from '../xml/dom.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Relationship } from '@docx4j/generated-objects-ts/modules/org_docx4j_relationships';
|
|
2
2
|
import { PartName } from '../opc/PartName.mjs';
|
|
3
3
|
import { ContentTypeManager } from '../opc/ContentTypeManager.mjs';
|
|
4
|
-
import type
|
|
4
|
+
import { type PartStore, type PartSink } from '../opc/PartStore.mjs';
|
|
5
5
|
import { type FlatOpcSinkOptions } from '../opc/FlatOpcPartStore.mjs';
|
|
6
6
|
import { type LoadOptions } from '../opc/Load.mjs';
|
|
7
7
|
import { Part, type RelationshipSource } from '../parts/Part.mjs';
|
|
@@ -49,6 +49,24 @@ export declare class OpcPackage implements RelationshipSource {
|
|
|
49
49
|
/** Adds empty core properties if absent (docx4j addDocPropsCorePart). */
|
|
50
50
|
addDocPropsCorePart(): DocPropsCorePart;
|
|
51
51
|
addDocPropsExtendedPart(): DocPropsExtendedPart;
|
|
52
|
+
/**
|
|
53
|
+
* A deep copy of the package, of the same class (docx4j `OpcPackage.clone()`).
|
|
54
|
+
*
|
|
55
|
+
* Made the way docx4j makes it, **through save and reload** — into a `MemoryPartStore` rather
|
|
56
|
+
* than a zip, so nothing is deflated — because that is the copy whose cost matches what was
|
|
57
|
+
* touched: a part nobody unmarshalled is copied as the bytes it was loaded with, byte for byte,
|
|
58
|
+
* and never parsed; an unmarshalled part is marshalled once and comes back in the clone as its
|
|
59
|
+
* own tree, unmarshalled again on demand, sharing nothing with this package's. (The alternative,
|
|
60
|
+
* a part-by-part copy with `deepCopy` on every unmarshalled tree, would have to unmarshal
|
|
61
|
+
* lazily anyway and would not be simpler.)
|
|
62
|
+
*
|
|
63
|
+
* The clone's `sourcePartStore` is that memory store, so it no longer depends on this package's
|
|
64
|
+
* container; the load options are this package's. Settings that are not in the package
|
|
65
|
+
* (`author`, `fonts`, tracking) are carried across by the subclasses.
|
|
66
|
+
*/
|
|
67
|
+
clone(): Promise<this>;
|
|
68
|
+
/** Carries the settings that are not in the package itself into a clone; subclasses add theirs. */
|
|
69
|
+
protected copyPackageSettingsTo(_target: OpcPackage): void;
|
|
52
70
|
/** The package as a zip. */
|
|
53
71
|
save(options?: {
|
|
54
72
|
level?: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PartName } from '../opc/PartName.mjs';
|
|
2
2
|
import { ContentTypeManager } from '../opc/ContentTypeManager.mjs';
|
|
3
|
+
import { MemoryPartSink } from '../opc/PartStore.mjs';
|
|
3
4
|
import { ZipPartStore, ZipPartSink } from '../opc/ZipPartStore.mjs';
|
|
4
5
|
import { FlatOpcPartStore, FlatOpcPartSink } from '../opc/FlatOpcPartStore.mjs';
|
|
5
6
|
import { loadPackage } from '../opc/Load.mjs';
|
|
@@ -101,6 +102,34 @@ export class OpcPackage {
|
|
|
101
102
|
}
|
|
102
103
|
return this.docPropsExtendedPart;
|
|
103
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* A deep copy of the package, of the same class (docx4j `OpcPackage.clone()`).
|
|
107
|
+
*
|
|
108
|
+
* Made the way docx4j makes it, **through save and reload** — into a `MemoryPartStore` rather
|
|
109
|
+
* than a zip, so nothing is deflated — because that is the copy whose cost matches what was
|
|
110
|
+
* touched: a part nobody unmarshalled is copied as the bytes it was loaded with, byte for byte,
|
|
111
|
+
* and never parsed; an unmarshalled part is marshalled once and comes back in the clone as its
|
|
112
|
+
* own tree, unmarshalled again on demand, sharing nothing with this package's. (The alternative,
|
|
113
|
+
* a part-by-part copy with `deepCopy` on every unmarshalled tree, would have to unmarshal
|
|
114
|
+
* lazily anyway and would not be simpler.)
|
|
115
|
+
*
|
|
116
|
+
* The clone's `sourcePartStore` is that memory store, so it no longer depends on this package's
|
|
117
|
+
* container; the load options are this package's. Settings that are not in the package
|
|
118
|
+
* (`author`, `fonts`, tracking) are carried across by the subclasses.
|
|
119
|
+
*/
|
|
120
|
+
async clone() {
|
|
121
|
+
const store = await this.saveTo(new MemoryPartSink());
|
|
122
|
+
const copy = await OpcPackage.load(store, this.loadOptions);
|
|
123
|
+
if (copy.constructor !== this.constructor) {
|
|
124
|
+
throw new Docx4JException(`Cloning ${this.constructor.name} produced ${copy.constructor.name}`);
|
|
125
|
+
}
|
|
126
|
+
this.copyPackageSettingsTo(copy);
|
|
127
|
+
return copy;
|
|
128
|
+
}
|
|
129
|
+
/** Carries the settings that are not in the package itself into a clone; subclasses add theirs. */
|
|
130
|
+
copyPackageSettingsTo(_target) {
|
|
131
|
+
// OpcPackage itself has none
|
|
132
|
+
}
|
|
104
133
|
/** The package as a zip. */
|
|
105
134
|
save(options) {
|
|
106
135
|
return this.saveTo(new ZipPartSink(options));
|
|
@@ -1,12 +1,82 @@
|
|
|
1
|
+
import type * as pml from '@docx4j/generated-objects-ts/modules/org_pptx4j_pml';
|
|
1
2
|
import { OpcPackage, type PackageSource } from './OpcPackage.mjs';
|
|
2
3
|
import type { LoadOptions } from '../opc/Load.mjs';
|
|
3
4
|
import type { Part } from '../parts/Part.mjs';
|
|
4
|
-
import
|
|
5
|
+
import { MainPresentationPart, SlidePart, SlideLayoutPart, SlideMasterPart, NotesMasterPart, PresentationPropertiesPart, ViewPropertiesPart, TableStylesPart, CommentAuthorsPart } from '../parts/pml/index.mjs';
|
|
6
|
+
import { type SlideTextOptions } from '../parts/pml/placeholders.mjs';
|
|
7
|
+
import { ThemePart } from '../parts/dml/index.mjs';
|
|
8
|
+
import { type FontSettings, type DefaultThemeValue } from '../model/fonts/defaultTheme.mjs';
|
|
9
|
+
/** docx4j / pptx4j `org.pptx4j.model.SlideSizesWellKnown`. */
|
|
10
|
+
export type SlideSizesWellKnown = 'LETTER' | 'A3' | 'A4' | 'B4JIS' | 'SCREEN4x3' | 'SCREEN16x9' | 'SCREEN16x10' | 'LEDGER' | 'B4ISO' | 'B5ISO' | 'MM35' | 'OVERHEAD' | 'BANNER';
|
|
11
|
+
/** docx4j `MainPresentationPart.createSlideSize(sz, landscape)`. */
|
|
12
|
+
export declare function createSlideSize(size: SlideSizesWellKnown, landscape?: boolean): pml.Presentation.SldSz;
|
|
13
|
+
export interface CreatePresentationOptions {
|
|
14
|
+
/** docx4j's `pptx4j.PageSize`; `'A4'` by default, as docx4j's property does. */
|
|
15
|
+
slideSize?: SlideSizesWellKnown;
|
|
16
|
+
/** docx4j's `pptx4j.PageOrientationLandscape`; true by default. */
|
|
17
|
+
landscape?: boolean;
|
|
18
|
+
/** Which Office theme the new presentation's theme part carries; see `pkg.fonts.defaultTheme`. */
|
|
19
|
+
defaultTheme?: DefaultThemeValue;
|
|
20
|
+
/** The first slide's title; the placeholder is left empty (PowerPoint's prompt) when absent. */
|
|
21
|
+
title?: string;
|
|
22
|
+
/** The first slide's body: a string, split on newlines, or one string per paragraph. */
|
|
23
|
+
body?: string | string[];
|
|
24
|
+
}
|
|
5
25
|
/** A pptx (docx4j PresentationMLPackage). */
|
|
6
26
|
export declare class PresentationMLPackage extends OpcPackage {
|
|
7
27
|
mainPresentationPart: MainPresentationPart | undefined;
|
|
28
|
+
/** The package's font settings, as `WordprocessingMLPackage.fonts`: which Office theme a new
|
|
29
|
+
* presentation's theme part carries. */
|
|
30
|
+
readonly fonts: FontSettings;
|
|
8
31
|
static load(source: PackageSource, options?: LoadOptions): Promise<PresentationMLPackage>;
|
|
32
|
+
/**
|
|
33
|
+
* A new presentation, as docx4j's `PresentationMLPackage.createPackage(sz, landscape)` builds
|
|
34
|
+
* one: the presentation part with the slide size, a slide master, a slide layout, a theme part
|
|
35
|
+
* in both the master's and the presentation's relationships, and — unlike docx4j, whose slide
|
|
36
|
+
* creation is commented out — one empty slide, so the file opens as a presentation rather than
|
|
37
|
+
* as an empty deck (CR-001 section 16).
|
|
38
|
+
*
|
|
39
|
+
* The master, layout and slide are docx4j's own template markup
|
|
40
|
+
* (`src/parts/pml/defaults.mts`); the theme is the Office theme `pkg.fonts.defaultTheme` names,
|
|
41
|
+
* the same one `WordprocessingMLPackage.createPackage` uses.
|
|
42
|
+
*
|
|
43
|
+
* The layout and the slide also take a title and a body placeholder, which docx4j's markup has
|
|
44
|
+
* not got: without them PowerPoint opens the slide blank, with no "Click to add title" to type
|
|
45
|
+
* into (CR-001 section 17). `title` and `body` fill the slide's; left out, it shows the prompts.
|
|
46
|
+
*/
|
|
47
|
+
static createPackage(options?: CreatePresentationOptions): Promise<PresentationMLPackage>;
|
|
48
|
+
/**
|
|
49
|
+
* Adds a slide part to the presentation (docx4j `MainPresentationPart.addSlide`), on the
|
|
50
|
+
* layout given or on the presentation's first layout. The slide carries a shape for each
|
|
51
|
+
* placeholder that layout defines, so that PowerPoint offers "Click to add title" on it;
|
|
52
|
+
* `title` and `body` fill them in (`body` is one paragraph per line). Appends, or inserts at
|
|
53
|
+
* `index`.
|
|
54
|
+
*/
|
|
55
|
+
addSlide(options?: {
|
|
56
|
+
index?: number;
|
|
57
|
+
layoutPart?: SlideLayoutPart;
|
|
58
|
+
partName?: string;
|
|
59
|
+
} & SlideTextOptions): Promise<SlidePart>;
|
|
60
|
+
/** `/ppt/slides/slideN.xml` for the lowest N the package has no part for. */
|
|
61
|
+
private nextSlideName;
|
|
9
62
|
setPartShortcut(part: Part, relationshipType: string): boolean;
|
|
10
63
|
getMainPresentationPart(): MainPresentationPart;
|
|
64
|
+
/** The slides, in `p:sldIdLst` order (docx4j `MainPresentationPart.getSlideParts()`). */
|
|
65
|
+
get slideParts(): SlidePart[];
|
|
66
|
+
/** The slides in `p:sldIdLst` order, unmarshalling the presentation part first. */
|
|
67
|
+
getSlideParts(): Promise<SlidePart[]>;
|
|
68
|
+
/** The slide masters, in `p:sldMasterIdLst` order. */
|
|
69
|
+
get slideMasterParts(): SlideMasterPart[];
|
|
70
|
+
/** Every slide layout of every master, masters in order and layouts in `p:sldLayoutIdLst` order. */
|
|
71
|
+
get slideLayoutParts(): SlideLayoutPart[];
|
|
72
|
+
get notesMasterPart(): NotesMasterPart | undefined;
|
|
73
|
+
get presentationPropertiesPart(): PresentationPropertiesPart | undefined;
|
|
74
|
+
get viewPropertiesPart(): ViewPropertiesPart | undefined;
|
|
75
|
+
get tableStylesPart(): TableStylesPart | undefined;
|
|
76
|
+
get commentAuthorsPart(): CommentAuthorsPart | undefined;
|
|
77
|
+
/** The theme related from the presentation part (docx4j `MainPresentationPart.getThemePart()`). */
|
|
78
|
+
get themePart(): ThemePart | undefined;
|
|
79
|
+
/** A clone carries the theme setting. */
|
|
80
|
+
protected copyPackageSettingsTo(target: OpcPackage): void;
|
|
11
81
|
protected get progId(): string;
|
|
12
82
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { createPresentation, createPresentationSldSz } from '@docx4j/generated-objects-ts/factory/org_pptx4j_pml';
|
|
1
2
|
import { OpcPackage } from './OpcPackage.mjs';
|
|
2
3
|
import { registerPackageClass } from './registry.mjs';
|
|
3
4
|
import { ContentTypes } from '../opc/ContentTypes.mjs';
|
|
4
5
|
import { Docx4JException } from '../opc/exceptions.mjs';
|
|
5
6
|
import { Namespaces } from '../parts/Namespaces.mjs';
|
|
7
|
+
import { MainPresentationPart, SlidePart, SlideLayoutPart, SlideMasterPart, } from '../parts/pml/index.mjs';
|
|
8
|
+
import { DEFAULT_SLIDE_MASTER_XML, DEFAULT_SLIDE_LAYOUT_XML, DEFAULT_SLIDE_XML } from '../parts/pml/defaults.mjs';
|
|
9
|
+
import { addShapes, layoutPlaceholders, slidePlaceholdersFor } from '../parts/pml/placeholders.mjs';
|
|
10
|
+
import { ThemePart } from '../parts/dml/index.mjs';
|
|
11
|
+
import { newFontSettings, themeOfSettings } from '../model/fonts/defaultTheme.mjs';
|
|
6
12
|
const MAIN_CONTENT_TYPES = [
|
|
7
13
|
ContentTypes.PRESENTATIONML_MAIN,
|
|
8
14
|
ContentTypes.PRESENTATIONML_TEMPLATE,
|
|
@@ -10,8 +16,41 @@ const MAIN_CONTENT_TYPES = [
|
|
|
10
16
|
ContentTypes.PRESENTATIONML_TEMPLATE_MACROENABLED,
|
|
11
17
|
ContentTypes.PRESENTATIONML_SLIDESHOW,
|
|
12
18
|
];
|
|
19
|
+
/**
|
|
20
|
+
* The landscape `cx` and `cy` in EMU, and the `p:sldSz/@type`, as docx4j's
|
|
21
|
+
* `MainPresentationPart.createSlideSize` has them. Portrait swaps the two.
|
|
22
|
+
* `B4JIS` is in the enumeration but has no size in docx4j, which throws for it; so does this.
|
|
23
|
+
*/
|
|
24
|
+
const SLIDE_SIZES = {
|
|
25
|
+
LETTER: [9144000, 6858000, 'letter'],
|
|
26
|
+
A3: [12801600, 9601200, 'A3'],
|
|
27
|
+
A4: [9906000, 6858000, 'A4'],
|
|
28
|
+
SCREEN4x3: [9144000, 6858000, 'screen4x3'],
|
|
29
|
+
SCREEN16x9: [9144000, 5143500, 'screen16x9'],
|
|
30
|
+
SCREEN16x10: [9144000, 5715000, 'screen16x10'],
|
|
31
|
+
LEDGER: [12179300, 9134475, 'ledger'],
|
|
32
|
+
B4ISO: [10826750, 8120063, 'B4ISO'],
|
|
33
|
+
B5ISO: [7169150, 5376863, 'B5ISO'],
|
|
34
|
+
MM35: [10287000, 6858000, '35mm'],
|
|
35
|
+
OVERHEAD: [9144000, 6858000, 'overhead'],
|
|
36
|
+
BANNER: [7315200, 914400, 'banner'],
|
|
37
|
+
};
|
|
38
|
+
/** docx4j `MainPresentationPart.createSlideSize(sz, landscape)`. */
|
|
39
|
+
export function createSlideSize(size, landscape = true) {
|
|
40
|
+
const dims = SLIDE_SIZES[size];
|
|
41
|
+
if (!dims)
|
|
42
|
+
throw new Docx4JException(`No support for slide size ${size}`);
|
|
43
|
+
const [cx, cy, type] = dims;
|
|
44
|
+
return createPresentationSldSz(landscape ? { cx, cy, type } : { cx: cy, cy: cx, type });
|
|
45
|
+
}
|
|
13
46
|
/** A pptx (docx4j PresentationMLPackage). */
|
|
14
47
|
export class PresentationMLPackage extends OpcPackage {
|
|
48
|
+
constructor() {
|
|
49
|
+
super(...arguments);
|
|
50
|
+
/** The package's font settings, as `WordprocessingMLPackage.fonts`: which Office theme a new
|
|
51
|
+
* presentation's theme part carries. */
|
|
52
|
+
this.fonts = newFontSettings();
|
|
53
|
+
}
|
|
15
54
|
static async load(source, options) {
|
|
16
55
|
var _a, _b;
|
|
17
56
|
const pkg = await OpcPackage.load(source, options);
|
|
@@ -20,6 +59,93 @@ export class PresentationMLPackage extends OpcPackage {
|
|
|
20
59
|
}
|
|
21
60
|
return pkg;
|
|
22
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A new presentation, as docx4j's `PresentationMLPackage.createPackage(sz, landscape)` builds
|
|
64
|
+
* one: the presentation part with the slide size, a slide master, a slide layout, a theme part
|
|
65
|
+
* in both the master's and the presentation's relationships, and — unlike docx4j, whose slide
|
|
66
|
+
* creation is commented out — one empty slide, so the file opens as a presentation rather than
|
|
67
|
+
* as an empty deck (CR-001 section 16).
|
|
68
|
+
*
|
|
69
|
+
* The master, layout and slide are docx4j's own template markup
|
|
70
|
+
* (`src/parts/pml/defaults.mts`); the theme is the Office theme `pkg.fonts.defaultTheme` names,
|
|
71
|
+
* the same one `WordprocessingMLPackage.createPackage` uses.
|
|
72
|
+
*
|
|
73
|
+
* The layout and the slide also take a title and a body placeholder, which docx4j's markup has
|
|
74
|
+
* not got: without them PowerPoint opens the slide blank, with no "Click to add title" to type
|
|
75
|
+
* into (CR-001 section 17). `title` and `body` fill the slide's; left out, it shows the prompts.
|
|
76
|
+
*/
|
|
77
|
+
static async createPackage(options = {}) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const pkg = new PresentationMLPackage();
|
|
80
|
+
if (options.defaultTheme !== undefined)
|
|
81
|
+
pkg.fonts.defaultTheme = options.defaultTheme;
|
|
82
|
+
// The presentation part (docx4j MainPresentationPart.createJaxbPresentationElement)
|
|
83
|
+
const pp = new MainPresentationPart();
|
|
84
|
+
pp.setContents(createPresentation({
|
|
85
|
+
sldMasterIdLst: { sldMasterId: [] },
|
|
86
|
+
sldIdLst: { sldId: [] },
|
|
87
|
+
sldSz: createSlideSize((_a = options.slideSize) !== null && _a !== void 0 ? _a : 'A4', (_b = options.landscape) !== null && _b !== void 0 ? _b : true),
|
|
88
|
+
notesSz: { cx: 6858000, cy: 9144000 },
|
|
89
|
+
}));
|
|
90
|
+
pkg.addTargetPart(pp);
|
|
91
|
+
// The layout, and the master that lists it. The layout defines the two placeholders a slide
|
|
92
|
+
// inherits its geometry from, so it is a Title and Content layout, not docx4j's empty one.
|
|
93
|
+
const layoutPart = new SlideLayoutPart();
|
|
94
|
+
layoutPart.setXml(DEFAULT_SLIDE_LAYOUT_XML);
|
|
95
|
+
const layout = await layoutPart.getContents();
|
|
96
|
+
layout.type = 'obj';
|
|
97
|
+
layout.preserve = true;
|
|
98
|
+
layout.cSld.name = 'Title and Content';
|
|
99
|
+
addShapes(layout.cSld.spTree, layoutPlaceholders(pp.contents.sldSz));
|
|
100
|
+
const masterPart = new SlideMasterPart();
|
|
101
|
+
pp.addSlideMasterIdListEntry(masterPart);
|
|
102
|
+
masterPart.setXml(DEFAULT_SLIDE_MASTER_XML);
|
|
103
|
+
await masterPart.getContents();
|
|
104
|
+
masterPart.addSlideLayoutIdListEntry(layoutPart);
|
|
105
|
+
layoutPart.addTargetPart(masterPart);
|
|
106
|
+
// The theme, in both places docx4j puts it (PowerPoint's own files relate it from the
|
|
107
|
+
// presentation part as well as from the master)
|
|
108
|
+
const theme = new ThemePart('/ppt/theme/theme1.xml');
|
|
109
|
+
theme.setXml(themeOfSettings(pkg.fonts).xml);
|
|
110
|
+
masterPart.addTargetPart(theme);
|
|
111
|
+
pp.addTargetPart(theme);
|
|
112
|
+
// One slide on the layout, with the layout's placeholders on it
|
|
113
|
+
const slidePart = new SlidePart();
|
|
114
|
+
slidePart.setXml(DEFAULT_SLIDE_XML);
|
|
115
|
+
await addSlidePlaceholders(slidePart, layout.cSld, options);
|
|
116
|
+
pp.addSlideIdListEntry(slidePart);
|
|
117
|
+
slidePart.addTargetPart(layoutPart);
|
|
118
|
+
return pkg;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Adds a slide part to the presentation (docx4j `MainPresentationPart.addSlide`), on the
|
|
122
|
+
* layout given or on the presentation's first layout. The slide carries a shape for each
|
|
123
|
+
* placeholder that layout defines, so that PowerPoint offers "Click to add title" on it;
|
|
124
|
+
* `title` and `body` fill them in (`body` is one paragraph per line). Appends, or inserts at
|
|
125
|
+
* `index`.
|
|
126
|
+
*/
|
|
127
|
+
async addSlide(options = {}) {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
const pp = this.getMainPresentationPart();
|
|
130
|
+
await pp.getContents();
|
|
131
|
+
const layoutPart = (_a = options.layoutPart) !== null && _a !== void 0 ? _a : (_b = this.slideMasterParts[0]) === null || _b === void 0 ? void 0 : _b.slideLayoutParts[0];
|
|
132
|
+
if (!layoutPart)
|
|
133
|
+
throw new Docx4JException('The presentation has no slide layout to put a slide on');
|
|
134
|
+
const slidePart = new SlidePart((_c = options.partName) !== null && _c !== void 0 ? _c : this.nextSlideName());
|
|
135
|
+
slidePart.setXml(DEFAULT_SLIDE_XML);
|
|
136
|
+
// readContents, not getContents: reading the layout must not cost it its byte-for-byte round trip
|
|
137
|
+
await addSlidePlaceholders(slidePart, (await layoutPart.readContents()).cSld, options);
|
|
138
|
+
pp.addSlide(slidePart, options.index, layoutPart);
|
|
139
|
+
return slidePart;
|
|
140
|
+
}
|
|
141
|
+
/** `/ppt/slides/slideN.xml` for the lowest N the package has no part for. */
|
|
142
|
+
nextSlideName() {
|
|
143
|
+
for (let n = 1;; n++) {
|
|
144
|
+
const name = `/ppt/slides/slide${n}.xml`;
|
|
145
|
+
if (!this.getPart(name))
|
|
146
|
+
return name;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
23
149
|
setPartShortcut(part, relationshipType) {
|
|
24
150
|
if (relationshipType === Namespaces.DOCUMENT || relationshipType === Namespaces.DOCUMENT_STRICT) {
|
|
25
151
|
this.mainPresentationPart = part;
|
|
@@ -32,8 +158,61 @@ export class PresentationMLPackage extends OpcPackage {
|
|
|
32
158
|
throw new Docx4JException('No main presentation part');
|
|
33
159
|
return this.mainPresentationPart;
|
|
34
160
|
}
|
|
161
|
+
/** The slides, in `p:sldIdLst` order (docx4j `MainPresentationPart.getSlideParts()`). */
|
|
162
|
+
get slideParts() {
|
|
163
|
+
var _a, _b;
|
|
164
|
+
return (_b = (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.slideParts) !== null && _b !== void 0 ? _b : [];
|
|
165
|
+
}
|
|
166
|
+
/** The slides in `p:sldIdLst` order, unmarshalling the presentation part first. */
|
|
167
|
+
async getSlideParts() {
|
|
168
|
+
return this.getMainPresentationPart().getSlideParts();
|
|
169
|
+
}
|
|
170
|
+
/** The slide masters, in `p:sldMasterIdLst` order. */
|
|
171
|
+
get slideMasterParts() {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
return (_b = (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.slideMasterParts) !== null && _b !== void 0 ? _b : [];
|
|
174
|
+
}
|
|
175
|
+
/** Every slide layout of every master, masters in order and layouts in `p:sldLayoutIdLst` order. */
|
|
176
|
+
get slideLayoutParts() {
|
|
177
|
+
return this.slideMasterParts.flatMap((m) => m.slideLayoutParts);
|
|
178
|
+
}
|
|
179
|
+
get notesMasterPart() {
|
|
180
|
+
var _a;
|
|
181
|
+
return (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.notesMasterPart;
|
|
182
|
+
}
|
|
183
|
+
get presentationPropertiesPart() {
|
|
184
|
+
var _a;
|
|
185
|
+
return (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.presentationPropertiesPart;
|
|
186
|
+
}
|
|
187
|
+
get viewPropertiesPart() {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.viewPropertiesPart;
|
|
190
|
+
}
|
|
191
|
+
get tableStylesPart() {
|
|
192
|
+
var _a;
|
|
193
|
+
return (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.tableStylesPart;
|
|
194
|
+
}
|
|
195
|
+
get commentAuthorsPart() {
|
|
196
|
+
var _a;
|
|
197
|
+
return (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.commentAuthorsPart;
|
|
198
|
+
}
|
|
199
|
+
/** The theme related from the presentation part (docx4j `MainPresentationPart.getThemePart()`). */
|
|
200
|
+
get themePart() {
|
|
201
|
+
var _a;
|
|
202
|
+
return (_a = this.mainPresentationPart) === null || _a === void 0 ? void 0 : _a.themePart;
|
|
203
|
+
}
|
|
204
|
+
/** A clone carries the theme setting. */
|
|
205
|
+
copyPackageSettingsTo(target) {
|
|
206
|
+
if (target instanceof PresentationMLPackage)
|
|
207
|
+
target.fonts.defaultTheme = this.fonts.defaultTheme;
|
|
208
|
+
}
|
|
35
209
|
get progId() {
|
|
36
210
|
return 'PowerPoint.Show';
|
|
37
211
|
}
|
|
38
212
|
}
|
|
213
|
+
/** The placeholder shapes of a new slide, matching the layout it is on (CR-001 section 17). */
|
|
214
|
+
async function addSlidePlaceholders(slidePart, layout, text) {
|
|
215
|
+
const sld = await slidePart.getContents();
|
|
216
|
+
addShapes(sld.cSld.spTree, slidePlaceholdersFor(layout, text));
|
|
217
|
+
}
|
|
39
218
|
registerPackageClass(MAIN_CONTENT_TYPES, PresentationMLPackage);
|
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
import { OpcPackage, type PackageSource } from './OpcPackage.mjs';
|
|
2
2
|
import type { LoadOptions } from '../opc/Load.mjs';
|
|
3
3
|
import type { Part } from '../parts/Part.mjs';
|
|
4
|
-
import
|
|
4
|
+
import { WorkbookPart, WorksheetPart, SharedStringsPart, StylesPart, CalcChainPart } from '../parts/sml/index.mjs';
|
|
5
|
+
import type { ThemePart } from '../parts/dml/index.mjs';
|
|
5
6
|
/** An xlsx (docx4j SpreadsheetMLPackage). */
|
|
6
7
|
export declare class SpreadsheetMLPackage extends OpcPackage {
|
|
7
8
|
workbookPart: WorkbookPart | undefined;
|
|
8
9
|
static load(source: PackageSource, options?: LoadOptions): Promise<SpreadsheetMLPackage>;
|
|
10
|
+
/**
|
|
11
|
+
* A new workbook with no sheets (docx4j `SpreadsheetMLPackage.createPackage()`): the workbook
|
|
12
|
+
* part, an empty `sheets`, and the one `bookViews/workbookView` docx4j adds because without it
|
|
13
|
+
* Excel 2010 could crash on print. Add sheets with `createWorksheetPart`.
|
|
14
|
+
*/
|
|
15
|
+
static createPackage(): Promise<SpreadsheetMLPackage>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a worksheet part, relates it from the workbook and adds the `sheet` entry that names
|
|
18
|
+
* it (docx4j `createWorksheetPart(partName, sheetName, sheetId)`). The part holds an empty
|
|
19
|
+
* `sheetData`, which is the least Excel will open.
|
|
20
|
+
*
|
|
21
|
+
* `index` inserts the tab at that position in `sheets` instead of appending. The part name
|
|
22
|
+
* defaults to the first free `/xl/worksheets/sheetN.xml` and the `sheetId` to the next free one.
|
|
23
|
+
*/
|
|
24
|
+
createWorksheetPart(name: string, index?: number, options?: {
|
|
25
|
+
partName?: string;
|
|
26
|
+
sheetId?: number;
|
|
27
|
+
}): WorksheetPart;
|
|
9
28
|
setPartShortcut(part: Part, relationshipType: string): boolean;
|
|
10
29
|
getWorkbookPart(): WorkbookPart;
|
|
30
|
+
/** The worksheets, in `sheets` order (the tab order Excel shows). */
|
|
31
|
+
get worksheetParts(): WorksheetPart[];
|
|
32
|
+
/** The worksheets in `sheets` order, unmarshalling the workbook part first. */
|
|
33
|
+
getWorksheetParts(): Promise<WorksheetPart[]>;
|
|
34
|
+
get sharedStringsPart(): SharedStringsPart | undefined;
|
|
35
|
+
get stylesPart(): StylesPart | undefined;
|
|
36
|
+
get calcChainPart(): CalcChainPart | undefined;
|
|
37
|
+
get themePart(): ThemePart | undefined;
|
|
38
|
+
/** `/xl/worksheets/sheetN.xml` for the lowest N the package has no part for. */
|
|
39
|
+
private nextWorksheetName;
|
|
11
40
|
protected get progId(): string;
|
|
12
41
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { createWorkbook, createSheet, createWorksheet } from '@docx4j/generated-objects-ts/factory/org_xlsx4j_sml';
|
|
1
2
|
import { OpcPackage } from './OpcPackage.mjs';
|
|
2
3
|
import { registerPackageClass } from './registry.mjs';
|
|
3
4
|
import { ContentTypes } from '../opc/ContentTypes.mjs';
|
|
4
5
|
import { Docx4JException } from '../opc/exceptions.mjs';
|
|
5
6
|
import { Namespaces } from '../parts/Namespaces.mjs';
|
|
7
|
+
import { WorkbookPart, WorksheetPart, } from '../parts/sml/index.mjs';
|
|
6
8
|
const MAIN_CONTENT_TYPES = [
|
|
7
9
|
ContentTypes.SPREADSHEETML_WORKBOOK,
|
|
8
10
|
ContentTypes.SPREADSHEETML_WORKBOOK_MACROENABLED,
|
|
@@ -19,6 +21,49 @@ export class SpreadsheetMLPackage extends OpcPackage {
|
|
|
19
21
|
}
|
|
20
22
|
return pkg;
|
|
21
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* A new workbook with no sheets (docx4j `SpreadsheetMLPackage.createPackage()`): the workbook
|
|
26
|
+
* part, an empty `sheets`, and the one `bookViews/workbookView` docx4j adds because without it
|
|
27
|
+
* Excel 2010 could crash on print. Add sheets with `createWorksheetPart`.
|
|
28
|
+
*/
|
|
29
|
+
static async createPackage() {
|
|
30
|
+
const pkg = new SpreadsheetMLPackage();
|
|
31
|
+
const wb = new WorkbookPart();
|
|
32
|
+
wb.setContents(createWorkbook({
|
|
33
|
+
bookViews: { workbookView: [{}] },
|
|
34
|
+
sheets: { sheet: [] },
|
|
35
|
+
}));
|
|
36
|
+
pkg.addTargetPart(wb);
|
|
37
|
+
return pkg;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a worksheet part, relates it from the workbook and adds the `sheet` entry that names
|
|
41
|
+
* it (docx4j `createWorksheetPart(partName, sheetName, sheetId)`). The part holds an empty
|
|
42
|
+
* `sheetData`, which is the least Excel will open.
|
|
43
|
+
*
|
|
44
|
+
* `index` inserts the tab at that position in `sheets` instead of appending. The part name
|
|
45
|
+
* defaults to the first free `/xl/worksheets/sheetN.xml` and the `sheetId` to the next free one.
|
|
46
|
+
*/
|
|
47
|
+
createWorksheetPart(name, index, options = {}) {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
const wb = this.getWorkbookPart();
|
|
50
|
+
const workbook = wb.contents;
|
|
51
|
+
const sheets = ((_a = workbook.sheets) !== null && _a !== void 0 ? _a : (workbook.sheets = { sheet: [] }));
|
|
52
|
+
const list = ((_b = sheets.sheet) !== null && _b !== void 0 ? _b : (sheets.sheet = []));
|
|
53
|
+
if (index !== undefined && (index < 0 || index > list.length)) {
|
|
54
|
+
throw new Docx4JException(`Can't add a sheet at index ${index}. (There are ${list.length} sheets) `);
|
|
55
|
+
}
|
|
56
|
+
const part = new WorksheetPart((_c = options.partName) !== null && _c !== void 0 ? _c : this.nextWorksheetName());
|
|
57
|
+
const rel = wb.addTargetPart(part);
|
|
58
|
+
const sheetId = (_d = options.sheetId) !== null && _d !== void 0 ? _d : list.reduce((max, s) => Math.max(max, s.sheetId), 0) + 1;
|
|
59
|
+
const entry = createSheet({ name, sheetId, id: rel.id });
|
|
60
|
+
if (index === undefined)
|
|
61
|
+
list.push(entry);
|
|
62
|
+
else
|
|
63
|
+
list.splice(index, 0, entry);
|
|
64
|
+
part.setContents(createWorksheet({ sheetData: {} }));
|
|
65
|
+
return part;
|
|
66
|
+
}
|
|
22
67
|
setPartShortcut(part, relationshipType) {
|
|
23
68
|
if (relationshipType === Namespaces.DOCUMENT || relationshipType === Namespaces.DOCUMENT_STRICT) {
|
|
24
69
|
this.workbookPart = part;
|
|
@@ -31,6 +76,39 @@ export class SpreadsheetMLPackage extends OpcPackage {
|
|
|
31
76
|
throw new Docx4JException('No workbook part');
|
|
32
77
|
return this.workbookPart;
|
|
33
78
|
}
|
|
79
|
+
/** The worksheets, in `sheets` order (the tab order Excel shows). */
|
|
80
|
+
get worksheetParts() {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
return (_b = (_a = this.workbookPart) === null || _a === void 0 ? void 0 : _a.worksheetParts) !== null && _b !== void 0 ? _b : [];
|
|
83
|
+
}
|
|
84
|
+
/** The worksheets in `sheets` order, unmarshalling the workbook part first. */
|
|
85
|
+
async getWorksheetParts() {
|
|
86
|
+
return this.getWorkbookPart().getWorksheetParts();
|
|
87
|
+
}
|
|
88
|
+
get sharedStringsPart() {
|
|
89
|
+
var _a;
|
|
90
|
+
return (_a = this.workbookPart) === null || _a === void 0 ? void 0 : _a.sharedStringsPart;
|
|
91
|
+
}
|
|
92
|
+
get stylesPart() {
|
|
93
|
+
var _a;
|
|
94
|
+
return (_a = this.workbookPart) === null || _a === void 0 ? void 0 : _a.stylesPart;
|
|
95
|
+
}
|
|
96
|
+
get calcChainPart() {
|
|
97
|
+
var _a;
|
|
98
|
+
return (_a = this.workbookPart) === null || _a === void 0 ? void 0 : _a.calcChainPart;
|
|
99
|
+
}
|
|
100
|
+
get themePart() {
|
|
101
|
+
var _a;
|
|
102
|
+
return (_a = this.workbookPart) === null || _a === void 0 ? void 0 : _a.themePart;
|
|
103
|
+
}
|
|
104
|
+
/** `/xl/worksheets/sheetN.xml` for the lowest N the package has no part for. */
|
|
105
|
+
nextWorksheetName() {
|
|
106
|
+
for (let n = 1;; n++) {
|
|
107
|
+
const name = `/xl/worksheets/sheet${n}.xml`;
|
|
108
|
+
if (!this.getPart(name))
|
|
109
|
+
return name;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
34
112
|
get progId() {
|
|
35
113
|
return 'Excel.Sheet';
|
|
36
114
|
}
|