@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
778 lines • 444 kB
JavaScript
import { ZipArchive, ZipArchiveItem } from '@syncfusion/ej2-compression';
import { XmlWriter } from '@syncfusion/ej2-file-utils';
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { HelperMethods } from '../index';
import { Dictionary, LocaleId } from '../../index';
import { nsidProperty } from '../../base/index';
import { sectionsProperty, hiddenProperty, paraStyleNameProperty, isLegalStyleNumberingProperty, breakClearTypeProperty, characterFormatProperty, paragraphFormatProperty, listsProperty, abstractListsProperty, backgroundProperty, stylesProperty, defaultTabWidthProperty, formattingProperty, trackChangesProperty, protectionTypeProperty, enforcementProperty, hashValueProperty, saltValueProperty, doNotUseHTMLParagraphAutoSpacingProperty, formFieldShadingProperty, footnotesProperty, endnotesProperty, compatibilityModeProperty, themeFontLanguagesProperty, themesProperty, nameProperty, basedOnProperty, nextProperty, linkProperty, localeIdProperty, localeIdFarEastProperty, localeIdBidiProperty, boldProperty, italicProperty, underlineProperty, fontHintTypeProperty, baselineAlignmentProperty, strikethroughProperty, highlightColorProperty, fontSizeProperty, fontColorProperty, fontFamilyProperty, styleNameProperty, bidiProperty, bdoProperty, fontSizeBidiProperty, fontFamilyBidiProperty, boldBidiProperty, italicBidiProperty, allCapsProperty, complexScriptProperty, fontFamilyAsciiProperty, fontFamilyFarEastProperty, fontFamilyNonFarEastProperty, revisionIdsProperty, listIdProperty, listLevelNumberProperty, leftIndentProperty, rightIndentProperty, firstLineIndentProperty, textAlignmentProperty, afterSpacingProperty, beforeSpacingProperty, spaceAfterAutoProperty, spaceBeforeAutoProperty, lineSpacingProperty, lineSpacingTypeProperty, listFormatProperty, keepWithNextProperty, widowControlProperty, keepLinesTogetherProperty, outlineLevelProperty, contextualSpacingProperty, bordersProperty, tabsProperty, headerDistanceProperty, footerDistanceProperty, differentFirstPageProperty, differentOddAndEvenPagesProperty, pageWidthProperty, pageHeightProperty, leftMarginProperty, rightMarginProperty, topMarginProperty, bottomMarginProperty, restartPageNumberingProperty, pageStartingNumberProperty, endnoteNumberFormatProperty, footNoteNumberFormatProperty, restartIndexForFootnotesProperty, restartIndexForEndnotesProperty, initialFootNoteNumberProperty, initialEndNoteNumberProperty, pageNumberStyleProperty, columnsProperty, numberOfColumnsProperty, equalWidthProperty, lineBetweenColumnsProperty, breakCodeProperty, columnSpanProperty, rowSpanProperty, verticalAlignmentProperty, allowBreakAcrossPagesProperty, isHeaderProperty, heightTypeProperty, gridBeforeProperty, gridBeforeWidthProperty, gridBeforeWidthTypeProperty, gridAfterProperty, gridAfterWidthProperty, gridAfterWidthTypeProperty, allowAutoFitProperty, cellSpacingProperty, shadingProperty, tableAlignmentProperty, preferredWidthProperty, preferredWidthTypeProperty, textureProperty, backgroundColorProperty, foregroundColorProperty, shadowProperty, hasNoneStyleProperty, verticalProperty, horizontalProperty, diagonalUpProperty, diagonalDownProperty, lineStyleProperty, lineWidthProperty, dataFormatProperty, yValueProperty, chartDataProperty, categoryXNameProperty, lineProperty, foreColorProperty, directionProperty, endStyleProperty, numberValueProperty, markerStyleProperty, markerSizeProperty, forwardProperty, backwardProperty, interceptProperty, isDisplayRSquaredProperty, isDisplayEquationProperty, seriesNameProperty, dataLabelProperty, errorBarProperty, seriesFormatProperty, trendLinesProperty, dataPointsProperty, firstSliceAngleProperty, holeSizeProperty, isLegendKeyProperty, isBubbleSizeProperty, isCategoryNameProperty, isSeriesNameProperty, isValueProperty, isPercentageProperty, isLeaderLinesProperty, showSeriesKeysProperty, hasHorizontalBorderProperty, hasVerticalBorderProperty, hasBordersProperty, categoryTypeProperty, chartCategoryProperty, chartSeriesProperty, chartTitleAreaProperty, chartLegendProperty, chartPrimaryCategoryAxisProperty, chartPrimaryValueAxisProperty, chartTitleProperty, chartTypeProperty, gapWidthProperty, overlapProperty, chartDataTableProperty, textProperty, shapeIdProperty, alternativeTextProperty, widthProperty, heightProperty, lineFormatProperty, fillFormatProperty, textWrappingStyleProperty, textWrappingTypeProperty, zOrderPositionProperty, layoutInCellProperty, lockAnchorProperty, autoShapeTypeProperty, textFrameProperty, colorProperty, fillProperty, textVerticalAlignmentProperty, imageStringProperty, metaFileImageStringProperty, isMetaFileProperty, topProperty, bottomProperty, rightProperty, leftProperty, formFieldDataProperty, fieldTypeProperty, textInputProperty, checkBoxProperty, dropDownListProperty, defaultValueProperty, formatProperty, sizeTypeProperty, sizeProperty, checkedProperty, dropDownItemsProperty, selectedIndexProperty, commentIdProperty, commentCharacterTypeProperty, footnoteTypeProperty, inlinesProperty, contentControlPropertiesProperty, lockContentControlProperty, lockContentsProperty, tagProperty, titleProperty, hasPlaceHolderTextProperty, multiLineProperty, isTemporaryProperty, dateCalendarTypeProperty, dateStorageFormatProperty, dateDisplayLocaleProperty, dateDisplayFormatProperty, isCheckedProperty, uncheckedStateProperty, checkedStateProperty, contentControlListItemsProperty, xmlMappingProperty, fontProperty, valueProperty, displayTextProperty, isMappedProperty, prefixMappingProperty, xPathProperty, storeItemIdProperty, cellFormatProperty, rowFormatProperty, cellsProperty, rowsProperty, descriptionProperty, wrapTextAroundProperty, positioningProperty, tableFormatProperty, allowOverlapProperty, distanceTopProperty, distanceRightProperty, distanceLeftProperty, distanceBottomProperty, verticalOriginProperty, verticalPositionProperty, horizontalOriginProperty, horizontalAlignmentProperty, horizontalPositionProperty, blocksProperty, headerProperty, footerProperty, evenHeaderProperty, evenFooterProperty, firstPageHeaderProperty, firstPageFooterProperty, headersFootersProperty, sectionFormatProperty, listLevelPatternProperty, followCharacterProperty, startAtProperty, levelNumberProperty, numberFormatProperty, abstractListIdProperty, levelsProperty, overrideListLevelProperty, levelOverridesProperty, separatorProperty, continuationSeparatorProperty, continuationNoticeProperty, bookmarkTypeProperty, propertiesProperty, tabJustificationProperty, positionProperty, deletePositionProperty, tabLeaderProperty, editRangeIdProperty, columnFirstProperty, columnLastProperty, userProperty, groupProperty, editableRangeStartProperty, spaceProperty, fontSchemeProperty, fontSchemeNameProperty, majorFontSchemeProperty, minorFontSchemeProperty, fontSchemeListProperty, fontTypefaceProperty, typefaceProperty, panoseProperty, typeProperty, majorUnitProperty, maximumValueProperty, minimumValueProperty, hasMajorGridLinesProperty, hasMinorGridLinesProperty, rgbProperty, appearanceProperty, lineFormatTypeProperty, allowSpaceOfSameStyleInTableProperty, weightProperty, fontNameProperty, columnIndexProperty, isAfterRowMarkProperty, isAfterParagraphMarkProperty, columnCountProperty, gridProperty, characterSpacingProperty, scalingProperty, horizontalRuleProperty, underlineColorProperty, isAutoMajorProperty } from '../../index';
/**
* Exports the document to Word format.
*/
var WordExport = /** @class */ (function () {
function WordExport() {
//Part path
this.customXMLItemsPath = 'customXml/item';
this.customXMLItemsPropspath = 'customXml/itemProps';
this.itemPropsPath = 'itemProps';
this.documentPath = 'word/document.xml';
this.stylePath = 'word/styles.xml';
this.chartPath = 'word/charts';
this.numberingPath = 'word/numbering.xml';
this.settingsPath = 'word/settings.xml';
this.headerPath = 'word/header';
this.footerPath = 'word/footer';
//private commentsPath: string = 'word/comments.xml';
this.imagePath = 'word/media/image';
this.footnotesPath = 'word/footnotes.xml';
this.endnotesPath = 'word/endnotes.xml';
this.appPath = 'docProps/app.xml';
this.corePath = 'docProps/core.xml';
// private CustomPath: string = 'docProps/custom.xml';
// private FontTablePath: string = 'word/fontTable.xml';
this.contentTypesPath = '[Content_Types].xml';
// private ChartsPath: string = 'word/charts/';
this.defaultEmbeddingPath = 'word/embeddings/';
this.commentsPath = 'word/comments.xml';
this.commentsExtendedPath = 'word/commentsExtended.xml';
// private EmbeddingPath:string = 'word\embeddings\';
// private DrawingPath:string = 'word\drawings\';
this.themePath = 'word/theme/theme1.xml';
// private FontsPath:string = 'word\fonts\';
// private DiagramPath:string = "word/diagrams/';
// private ControlPath:string = "word/activeX/';
// private VbaProject: string = 'vbaProject.bin';
// private VbaData: string = 'vbaData.xml';
// private VbaProjectPath: string = 'word/vbaProject.bin';
// private VbaDataPath: string = 'word/vbaData.xml';
// private CustomXMLPath:string = 'customXml\';
//Relationship path
this.generalRelationPath = '_rels/.rels';
this.wordRelationPath = 'word/_rels/document.xml.rels';
this.customXMLRelPath = 'customXml/_rels/item';
this.excelRelationPath = 'xl/_rels/workbook.xml.rels';
// private FontRelationPath: string = 'word/_rels/fontTable.xml.rels';
// private CommentsRelationPath: string = 'word/_rels/comments.xml.rels';
this.footnotesRelationPath = 'word/_rels/footnotes.xml.rels';
this.endnotesRelationPath = 'word/_rels/endnotes.xml.rels';
// private NumberingRelationPath: string = 'word/_rels/numbering.xml.rels';
this.headerRelationPath = 'word/_rels/header';
this.footerRelationPath = 'word/_rels/footer';
// private SettingsRelationpath: string = 'word/_rels/settings.xml.rels';
// private VbaProjectRelsPath: string = 'word/_rels/vbaProject.bin.rels';
//Content type of the parts
this.xmlContentType = 'application/xml';
this.fontContentType = 'application/vnd.openxmlformats-officedocument.obfuscatedFont';
this.documentContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml';
this.TemplateContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml';
// private CommentsContentType: string = 'application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml';
this.settingsContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml';
this.commentsContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml';
this.commentsExContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml';
this.endnoteContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml';
// private FontTableContentType: string = 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml';
this.footerContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml';
this.footnoteContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml';
// private GlossaryDocumentContentType: string = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml';
this.headerContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml';
this.numberingContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml';
this.stylesContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml';
this.webSettingsContentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml';
this.appContentType = 'application/vnd.openxmlformats-officedocument.extended-properties+xml';
this.coreContentType = 'application/vnd.openxmlformats-package.core-properties+xml';
this.customContentType = 'application/vnd.openxmlformats-officedocument.custom-properties+xml';
this.customXmlContentType = 'application/vnd.openxmlformats-officedocument.customXmlProperties+xml';
this.relationContentType = 'application/vnd.openxmlformats-package.relationships+xml';
// private DiagramColor: string = 'application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml';
// private DiagramData: string = 'application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml';
// private DiagramLayout: string = 'application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml';
// private DiagramStyle: string = 'application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml';
this.chartsContentType = 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml';
this.themeContentType = 'application/vnd.openxmlformats-officedocument.theme+xml';
// private ChartDrawingContentType: string = 'application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml';
// private ActiveXContentType: string = 'application/vnd.ms-office.activeX+xml';
// private ActiveXBinContentType: string = 'application/vnd.ms-office.activeX';
this.tableStyleContentType = 'application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml';
// private ChartStyleContentType: string = 'application/vnd.ms-office.chartstyle+xml';
this.chartColorStyleContentType = 'application/vnd.ms-office.chartcolorstyle+xml';
// private VbaProjectContentType: string = 'application/vnd.ms-office.vbaProject';
// private VbaDataContentType: string = 'application/vnd.ms-word.vbaData+xml';
// private MacroDocumentContentType: string = 'application/vnd.ms-word.document.macroEnabled.main+xml';
// private MacroTemplateContentType: string = 'application/vnd.ms-word.template.macroEnabledTemplate.main+xml';
// private OleObjectContentType: string = 'application/vnd.openxmlformats-officedocument.oleObject';
// Relationship types of document parts
// private AltChunkRelType: string = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk';
this.commentsRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments';
this.commentsExRelType = 'http://schemas.microsoft.com/office/2011/relationships/commentsExtended';
this.settingsRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings';
this.endnoteRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes';
// private FontTableRelType: string = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable';
this.footerRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer';
this.footnoteRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes';
this.headerRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header';
this.documentRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
this.numberingRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering';
this.stylesRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles';
// private OleObjectRelType: string = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject';
this.chartRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart';
this.ThemeRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme';
this.fontRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/font';
this.tableStyleRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles';
this.coreRelType = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';
this.appRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties';
this.customRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties';
this.imageRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image';
this.hyperlinkRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink';
this.controlRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/control';
this.packageRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package';
// private VbaProjectRelType: string = 'http://schemas.microsoft.com/office/2006/relationships/vbaProject';
// private VbaDataRelType: string = 'http://schemas.microsoft.com/office/2006/relationships/wordVbaData';
this.customXmlRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml';
this.customUIRelType = 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility';
this.attachedTemplateRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate';
this.chartColorStyleRelType = 'http://schemas.microsoft.com/office/2011/relationships/chartColorStyle';
// private ChartStyleRelType: string = 'http://schemas.microsoft.com/office/2011/relationships/chartStyle';
// private ChartUserShapesRelType: string = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartUserShapes';
// private ChartContentType: string = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package';
// Namespaces
// private PKG_namespace: string = 'http://schemas.microsoft.com/office/2006/xmlPackage';
this.wNamespace = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
this.wpNamespace = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing';
this.pictureNamespace = 'http://schemas.openxmlformats.org/drawingml/2006/picture';
this.aNamespace = 'http://schemas.openxmlformats.org/drawingml/2006/main';
this.a14Namespace = 'http://schemas.microsoft.com/office/drawing/2010/main';
this.svgNamespace = 'http://schemas.microsoft.com/office/drawing/2016/SVG/main';
this.rNamespace = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
this.rpNamespace = 'http://schemas.openxmlformats.org/package/2006/relationships';
this.vNamespace = 'urn:schemas-microsoft-com:vml';
this.oNamespace = 'urn:schemas-microsoft-com:office:office';
this.xmlNamespace = 'http://www.w3.org/XML/1998/namespace';
this.w10Namespace = 'urn:schemas-microsoft-com:office:word';
this.cpNamespace = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties';
this.dcNamespace = 'http://purl.org/dc/elements/1.1/';
// private DCTERMS_namespace: string = 'http://purl.org/dc/terms/';
// private XSI_namespace: string = 'http://www.w3.org/2001/XMLSchema-instance';
this.docPropsNamespace = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties';
this.veNamespace = 'http://schemas.openxmlformats.org/markup-compatibility/2006';
this.mNamespace = 'http://schemas.openxmlformats.org/officeDocument/2006/math';
this.wneNamespace = 'http://schemas.microsoft.com/office/word/2006/wordml';
// private DCMI_namespace: string = 'http://purl.org/dc/dcmitype/';
this.customPropsNamespace = 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties';
this.vtNamespace = 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes';
this.chartNamespace = 'http://schemas.openxmlformats.org/drawingml/2006/chart';
this.slNamespace = 'http://schemas.openxmlformats.org/schemaLibrary/2006/main';
//2003WML namespace
// private amlNamespace: string = 'http://schemas.microsoft.com/aml/2001/core';
this.dtNamespace = 'uuid:C2F41010-65B3-11d1-A29F-00AA00C14882';
this.wmlNamespace = 'http://schemas.microsoft.com/office/word/2003/wordml';
//2010 namespaces
this.w14Namespace = 'http://schemas.microsoft.com/office/word/2010/wordml';
this.wpCanvasNamespace = 'http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas';
this.wpDrawingNamespace = 'http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing';
this.wpGroupNamespace = 'http://schemas.microsoft.com/office/word/2010/wordprocessingGroup';
this.wpInkNamespace = 'http://schemas.microsoft.com/office/word/2010/wordprocessingInk';
this.wpShapeNamespace = 'http://schemas.microsoft.com/office/word/2010/wordprocessingShape';
//2013 namespaces
this.w15Namespace = 'http://schemas.microsoft.com/office/word/2012/wordml';
this.diagramNamespace = 'http://schemas.openxmlformats.org/drawingml/2006/diagram';
//Encryption namespaces
this.eNamespace = 'http://schemas.microsoft.com/office/2006/encryption';
this.pNamespace = 'http://schemas.microsoft.com/office/2006/keyEncryptor/password';
this.certNamespace = 'http://schemas.microsoft.com/office/2006/keyEncryptor/certificate';
this.cxNamespace = 'http://schemas.microsoft.com/office/drawing/2014/chartex';
// chart
this.c15Namespace = 'http://schemas.microsoft.com/office/drawing/2015/06/chart';
this.c7Namespace = 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart';
this.csNamespace = 'http://schemas.microsoft.com/office/drawing/2012/chartStyle';
// worksheet
this.spreadSheetNamespace = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';
this.spreadSheet9 = 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main';
// Dls xml tags
this.cRelationshipsTag = 'Relationships';
this.cRelationshipTag = 'Relationship';
this.cIdTag = 'Id';
this.cTypeTag = 'Type';
this.cTargetTag = 'Target';
this.cUserShapesTag = 'userShapes';
this.cExternalData = 'externalData';
this.twipsInOnePoint = 20;
this.twentiethOfPoint = 20;
this.borderMultiplier = 8;
this.percentageFactor = 50;
this.emusPerPoint = 12700;
// private const TOC_SYMBOL:string = (char)0x01;
// private const FOOTNOTE_SYMBOL:string = (char)0x02;
// private const PAGENUMBER_SYMBOL:string = (char)0xB;
// private DEF_FIT_TEXT_TO_SHAPE: string = 'mso-fit-shape-to-text:t';
// Document tags
this.cConditionalTableStyleTag = 'tblStylePr';
this.cTableFormatTag = 'tblPr';
this.cTowFormatTag = 'trPr';
this.cCellFormatTag = 'tcPr';
this.cParagraphFormatTag = 'pPr';
this.cCharacterFormatTag = 'rPr';
this.packageType = 'http://schemas.microsoft.com/office/2006/xmlPackage';
this.relsPartPath = '/_rels/.rels';
this.documentRelsPartPath = '/word/_rels/document.xml.rels';
this.webSettingsPath = '/word/webSettings.xml';
this.wordMLDocumentPath = '/word/document.xml';
this.wordMLStylePath = '/word/styles.xml';
this.wordMLNumberingPath = '/word/numbering.xml';
this.wordMLSettingsPath = '/word/settings.xml';
this.wordMLHeaderPath = '/word/header';
this.wordMLFooterPath = '/word/footer';
this.wordMLCommentsPath = '/word/comments.xml';
this.wordMLImagePath = '/word/media/image';
this.wordMLFootnotesPath = '/word/footnotes.xml';
this.wordMLEndnotesPath = '/word/endnotes.xml';
this.wordMLAppPath = '/docProps/app.xml';
this.wordMLCorePath = '/docProps/core.xml';
this.wordMLCustomPath = '/docProps/custom.xml';
this.wordMLFontTablePath = '/word/fontTable.xml';
this.wordMLChartsPath = '/word/charts/';
this.wordMLDefaultEmbeddingPath = '/word/embeddings/';
this.wordMLEmbeddingPath = '/word/embeddings/';
this.wordMLDrawingPath = '/word/drawings/';
this.wordMLThemePath = '/word/theme/theme1.xml';
this.wordMLFontsPath = '/word/fonts/';
this.wordMLDiagramPath = '/word/diagrams/';
this.wordMLControlPath = '/word/activeX/';
this.wordMLVbaProject = '/vbaProject.bin';
this.wordMLVbaData = '/vbaData.xml';
this.wordMLVbaProjectPath = '/word/vbaProject.bin';
this.wordMLVbaDataPath = '/word/vbaData.xml';
// private WordMLCustomXMLPath: string = '/customXml/';
this.wordMLWebSettingsPath = '/word/webSettings.xml';
this.wordMLCustomItemProp1Path = '/customXml/itemProps1.xml';
// private WordMLCustomXMLRelPath: string = '/customXml/_rels/item1.xml.rels';
this.wordMLFootnoteRelPath = '/word/_rels/footnotes.xml.rels';
this.wordMLEndnoteRelPath = '/word/_rels/endnotes.xml.rels';
this.wordMLSettingsRelPath = '/word/_rels/settings.xml.rels';
this.wordMLNumberingRelPath = '/word/_rels/numbering.xml.rels';
this.wordMLFontTableRelPath = '/word/_rels/fontTable.xml.rels';
this.wordMLCustomXmlPropsRelType = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps';
this.wordMLControlRelType = 'http://schemas.microsoft.com/office/2006/relationships/activeXControlBinary';
this.wordMLDiagramContentType = 'application/vnd.ms-office.drawingml.diagramDrawing+xml';
this.dsNamespace = 'http://schemas.openxmlformats.org/officeDocument/2006/customXml';
this.excelFiles = undefined;
this.lastSection = false;
this.mRelationShipID = 0;
this.cRelationShipId = 0;
this.eRelationShipId = 0;
this.efRelationShipId = 0;
this.mDocPrID = 1;
this.chartCount = 0;
this.seriesCount = 0;
this.chartStringCount = 0;
this.mDifferentFirstPage = false;
this.mBookmarks = undefined;
this.mComments = [];
this.revisions = [];
this.customXMLProps = [];
this.paraID = 0;
this.commentParaID = 0;
this.commentParaIDInfo = {};
this.isInsideComment = false;
this.commentId = {};
this.currentCommentId = 0;
this.trackChangesId = 0;
this.prevRevisionIds = [];
this.isRevisionContinuous = false;
this.isBookmarkAtEnd = false;
this.isBookmarkAtRowEnd = false;
this.isVerticalMergeCell = false;
this.keywordIndex = undefined;
this.isHeaderFooter = false;
this.isSerializeFootEndNote = undefined;
this.containerWidth = 0;
}
WordExport.prototype.getModuleName = function () {
return 'WordExport';
};
Object.defineProperty(WordExport.prototype, "bookmarks", {
// Gets the bookmark name
get: function () {
if (isNullOrUndefined(this.mBookmarks)) {
this.mBookmarks = [];
}
return this.mBookmarks;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "documentImages", {
// Gets the collection of images present in the document body
get: function () {
if (this.mDocumentImages === undefined) {
this.mDocumentImages = new Dictionary();
}
return this.mDocumentImages;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "svgImages", {
// Gets the collection of images present in the document body
get: function () {
if (this.mSvgImages === undefined) {
this.mSvgImages = new Dictionary();
}
return this.mSvgImages;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "externalImages", {
// Gets the collection of images present in the document body
get: function () {
if (this.mExternalLinkImages === undefined) {
this.mExternalLinkImages = new Dictionary();
}
return this.mExternalLinkImages;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "headerFooterImages", {
// Gets the collections of images present in the HeaderFooters
get: function () {
if (this.mHeaderFooterImages === undefined) {
this.mHeaderFooterImages = new Dictionary();
}
return this.mHeaderFooterImages;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "headerFooterSvgImages", {
// Gets the collections of images present in the HeaderFooters
get: function () {
if (this.mHeaderFooterSvgImages === undefined) {
this.mHeaderFooterSvgImages = new Dictionary();
}
return this.mHeaderFooterSvgImages;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "documentCharts", {
// Gets the collection of charts present in the document body
get: function () {
if (this.mDocumentCharts === undefined) {
this.mDocumentCharts = new Dictionary();
}
return this.mDocumentCharts;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "headersFooters", {
/// Gets the HeaderFooter Collection
get: function () {
if (this.mHeaderFooterColl === undefined) {
this.mHeaderFooterColl = new Dictionary();
}
return this.mHeaderFooterColl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WordExport.prototype, "endnotesFootnotes", {
/// Gets the Endnote and Footnote Collection
get: function () {
if (this.mFootEndnotesColl === undefined) {
this.mFootEndnotesColl = new Dictionary();
}
return this.mFootEndnotesColl;
},
enumerable: true,
configurable: true
});
/**
* @private
* @param {DocumentHelper} documentHelper - Document helper
* @param {string} fileName - file name
* @param {string} formatType - format type
* @returns {void}
*/
WordExport.prototype.save = function (documentHelper, fileName, formatType) {
var _this = this;
this.fileName = fileName;
this.serialize(documentHelper, formatType);
var excelFiles = this.serializeExcelFiles();
if (excelFiles && excelFiles.length > 0) {
Promise.all(excelFiles).then(function () {
_this.saveInternal(fileName, formatType);
});
}
else {
this.saveInternal(fileName, formatType);
}
this.close();
};
WordExport.prototype.saveInternal = function (fileName, formatType) {
if (formatType === 'Docx') {
this.mArchive.save(fileName + '.docx').then(function (mArchive) {
mArchive.destroy();
});
}
else if (formatType === 'Dotx') {
this.mArchive.save(fileName + '.dotx').then(function (mArchive) {
mArchive.destroy();
});
}
};
/**
* @private
* @param {DocumentHelper} documentHelper - Document helper
* @param {string} formatType - format type
* @returns {Promise<Blob>} - Return Promise
*/
WordExport.prototype.saveAsBlob = function (documentHelper, formatType) {
var _this = this;
this.serialize(documentHelper, formatType);
var excelFiles = this.serializeExcelFiles();
/* eslint-disable */
return new Promise(function (resolve, reject) {
if (excelFiles.length > 0) {
Promise.all(excelFiles).then(function () {
_this.mArchive.saveAsBlob().then(function (blob) {
_this.mArchive.destroy();
blob = new Blob([blob], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
resolve(blob);
});
});
}
else {
_this.mArchive.saveAsBlob().then(function (blob) {
_this.mArchive.destroy();
blob = new Blob([blob], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
resolve(blob);
});
}
});
/* eslint-enable */
};
WordExport.prototype.serializeExcelFiles = function () {
var _this = this;
var excelFiles = this.excelFiles;
var files = [];
if (excelFiles && excelFiles.length > 0) {
var _loop_1 = function (i) {
var fileName = excelFiles.keys[parseInt(i.toString(), 10)];
var excelFile = excelFiles.get(fileName);
var excelPromise = excelFile.saveAsBlob();
files.push(excelPromise);
excelPromise.then(function (blob) {
var zipArchiveItem = new ZipArchiveItem(blob, fileName);
_this.mArchive.addItem(zipArchiveItem);
});
};
for (var i = 0; i < excelFiles.length; i++) {
_loop_1(i);
}
this.excelFiles.clear();
}
return files;
};
/**
* @private
* @returns {void}
*/
WordExport.prototype.saveExcel = function () {
var xlsxPath = this.defaultEmbeddingPath + 'Microsoft_Excel_Worksheet' + this.chartCount + '.xlsx';
this.excelFiles.add(xlsxPath, this.mArchiveExcel);
this.mArchiveExcel = undefined;
};
/**
* @private
* @returns {void}
*/
WordExport.prototype.destroy = function () {
this.clearDocument();
this.mRelationShipID = undefined;
this.mDocPrID = undefined;
this.mDifferentFirstPage = undefined;
this.fileName = undefined;
this.imageRelationIds = undefined;
this.svgImageRelationIds = undefined;
if (this.mArchive) {
this.mArchive.destroy();
this.mArchive = undefined;
}
if (this.mArchiveExcel) {
this.mArchiveExcel.destroy();
this.mArchiveExcel = undefined;
}
};
// Saves the word document in the stream
WordExport.prototype.serialize = function (documentHelper, formatType) {
this.keywordIndex = documentHelper.owner.documentEditorSettings.optimizeSfdt ? 1 : 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
var document = documentHelper.owner.sfdtExportModule.write(this.keywordIndex);
this.setDocument(document);
this.mComments = documentHelper.comments;
this.mCustomXML = documentHelper.customXmlData;
this.mImages = documentHelper.images;
this.revisions = documentHelper.owner.revisions.changes;
this.mArchive = new ZipArchive();
this.mArchive.compressionLevel = 'Normal';
this.commentParaIDInfo = {};
this.commentParaID = 0;
this.currentCommentId = 0;
this.commentId = {};
this.mVerticalMerge = new Dictionary();
this.mGridSpans = new Dictionary();
this.imageRelationIds = new Dictionary();
this.svgImageRelationIds = new Dictionary();
var contenttype;
//document.xml
this.serializeDocument();
//Styles.xml
this.serializeStyles();
//numbering.xml
this.serializeNumberings();
//comments.xml
this.serializeComments();
//commentsExtended.xml
this.serializeCommentsExtended();
//theme.xml
// if (m_document.DocHasThemes && !isNullOrUndefined(m_document.Themes))
this.serializeThemes();
// else
// this.serializeDefaultThemes();
//settings.xml
this.serializeSettings();
//core.xml
this.serializeCoreProperties();
//app.xml
this.serializeAppProperties();
//fontTable.xml
this.serializeFontTable(contenttype);
//custom.xml
// if (!isNullOrUndefined(this.wordDocument.CustomDocumentProperties) && m_document.CustomDocumentProperties.length > 0) {
// SerializeCustomProperties();
// }
//Settings Relations
this.serializeSettingsRelation();
//Numbering relation if the document has picture bullet
// if (PictureBullets.length > 0) {
// SerializeNumberingsRelation();
// }
this.serializeHeaderFooters();
this.serializeFootnotes();
this.serializeEndnotes();
//document relations
this.serializeDocumentRelations();
// Add controls to archieve.
// if (ControlsPathNames.length > 0) {
// AddControlsToZip(m_document.DocxPackage);
// }
// if (!isNullOrUndefined(m_document.CustomUIPartContainer))
// AddPartContainerToArchive(m_document.CustomUIPartContainer);
// if (!isNullOrUndefined(m_document.CustomXMLContainer))
// AddPartContainerToArchive(m_document.CustomXMLContainer);
//general relations
this.serializeGeneralRelations();
//[ContentTypes].xml
this.serializeContentTypes(contenttype, formatType);
// Clears the internal fields maintained for serializing.
this.clearDocument();
};
// Sets the document
WordExport.prototype.setDocument = function (document, keyindex) {
if (isNullOrUndefined(this.keywordIndex)) {
this.keywordIndex = keyindex;
}
this.document = document;
this.mSections = document[sectionsProperty[this.keywordIndex]];
this.mLists = document[listsProperty[this.keywordIndex]];
this.mAbstractLists = document[abstractListsProperty[this.keywordIndex]];
this.defCharacterFormat = document[characterFormatProperty[this.keywordIndex]];
this.defParagraphFormat = document[paragraphFormatProperty[this.keywordIndex]];
this.defaultTabWidthValue = document[defaultTabWidthProperty[this.keywordIndex]];
this.themeFontLang = document[themeFontLanguagesProperty[this.keywordIndex]];
this.dontUseHtmlParagraphAutoSpacing = HelperMethods.parseBoolValue(document[doNotUseHTMLParagraphAutoSpacingProperty[this.keywordIndex]]);
this.mStyles = document[stylesProperty[this.keywordIndex]];
this.mThemes = document[themesProperty[this.keywordIndex]];
this.formatting = HelperMethods.parseBoolValue(document[formattingProperty[this.keywordIndex]]);
this.enforcement = HelperMethods.parseBoolValue(document[enforcementProperty[this.keywordIndex]]);
this.hashValue = document[hashValueProperty[this.keywordIndex]];
this.saltValue = document[saltValueProperty[this.keywordIndex]];
this.protectionType = document[protectionTypeProperty[this.keywordIndex]];
this.formFieldShading = HelperMethods.parseBoolValue(document[formFieldShadingProperty[this.keywordIndex]]);
this.trackChanges = HelperMethods.parseBoolValue(document[trackChangesProperty[this.keywordIndex]]);
this.compatibilityMode = document[compatibilityModeProperty[this.keywordIndex]];
this.allowSpaceOfSameStyleInTable = HelperMethods.parseBoolValue(document[allowSpaceOfSameStyleInTableProperty[this.keywordIndex]]);
};
// Clears the document
WordExport.prototype.clearDocument = function () {
// Owner Nodes
this.section = undefined;
this.lastSection = undefined;
this.blockOwner = undefined;
this.paragraph = undefined;
this.table = undefined;
this.row = undefined;
this.headerFooter = undefined;
this.commentParaIDInfo = {};
this.commentParaID = 0;
this.currentCommentId = 0;
this.commentId = {};
this.document = undefined;
this.mSections = undefined;
this.mLists = undefined;
this.mAbstractLists = undefined;
this.defCharacterFormat = undefined;
this.defParagraphFormat = undefined;
this.defaultTabWidthValue = undefined;
this.trackChanges = undefined;
this.customXMLProps = [];
this.mRelationShipID = 0;
this.eRelationShipId = 0;
this.cRelationShipId = 0;
this.efRelationShipId = 0;
this.mDocPrID = 1;
this.chartCount = 0;
this.keywordIndex = undefined;
this.mDifferentFirstPage = false;
if (this.mHeaderFooterColl) {
this.mHeaderFooterColl.destroy();
this.mHeaderFooterColl = undefined;
}
if (this.mVerticalMerge) {
this.mVerticalMerge.destroy();
this.mVerticalMerge = undefined;
}
if (this.mGridSpans) {
this.mGridSpans.destroy();
this.mGridSpans = undefined;
}
if (this.mDocumentImages) {
this.mDocumentImages.destroy();
this.mDocumentImages = undefined;
}
if (this.mSvgImages) {
this.mSvgImages.destroy();
this.mSvgImages = undefined;
}
if (this.mExternalLinkImages) {
this.mExternalLinkImages.destroy();
this.mExternalLinkImages = undefined;
}
if (this.mHeaderFooterImages) {
this.mHeaderFooterImages.destroy();
this.mHeaderFooterImages = undefined;
}
if (this.mHeaderFooterSvgImages) {
this.mHeaderFooterSvgImages.destroy();
this.mHeaderFooterSvgImages = undefined;
}
if (this.mDocumentCharts) {
this.mDocumentCharts.destroy();
this.mDocumentCharts = undefined;
}
if (this.mFootEndnotesColl) {
this.mFootEndnotesColl.destroy();
this.mFootEndnotesColl = undefined;
}
};
// Serializes the document elements (document.xml)
WordExport.prototype.serializeDocument = function () {
var writer = new XmlWriter();
writer.writeStartElement('w', 'document', this.wNamespace);
this.writeCommonAttributeStrings(writer);
writer.writeStartElement('w', 'background', this.wNamespace);
writer.writeAttributeString('w', 'color', undefined, this.getColor(this.document[backgroundProperty[this.keywordIndex]][colorProperty[this.keywordIndex]]));
writer.writeEndElement();
this.serializeDocumentBody(writer);
writer.writeEndElement(); //end of document tag
var archiveItem = new ZipArchiveItem(writer.buffer, this.documentPath);
this.mArchive.addItem(archiveItem);
};
WordExport.prototype.writeCommonAttributeStrings = function (writer) {
writer.writeAttributeString('xmlns', 'wpc', undefined, this.wpCanvasNamespace);
this.writeCustom(writer);
writer.writeAttributeString('xmlns', 'wp14', undefined, this.wpDrawingNamespace);
writer.writeAttributeString('xmlns', 'wp', undefined, this.wpNamespace);
writer.writeAttributeString('xmlns', 'w10', undefined, this.w10Namespace);
writer.writeAttributeString('xmlns', 'w', undefined, this.wNamespace);
this.writeDup(writer);
writer.writeAttributeString('xmlns', 'wne', undefined, this.wneNamespace);
writer.writeAttributeString('xmlns', 'wps', undefined, this.wpShapeNamespace);
writer.writeAttributeString('mc', 'Ignorable', undefined, 'w14 w15 wp14');
};
WordExport.prototype.writeDup = function (writer) {
writer.writeAttributeString('xmlns', 'w14', undefined, this.w14Namespace);
writer.writeAttributeString('xmlns', 'w15', undefined, this.w15Namespace);
writer.writeAttributeString('xmlns', 'wpg', undefined, this.wpGroupNamespace);
writer.writeAttributeString('xmlns', 'wpi', undefined, this.wpInkNamespace);
};
WordExport.prototype.writeCustom = function (writer) {
writer.writeAttributeString('xmlns', 'mc', undefined, this.veNamespace);
writer.writeAttributeString('xmlns', 'o', undefined, this.oNamespace);
writer.writeAttributeString('xmlns', 'r', undefined, this.rNamespace);
writer.writeAttributeString('xmlns', 'm', undefined, this.mNamespace);
writer.writeAttributeString('xmlns', 'v', undefined, this.vNamespace);
};
// Serializes the document body
WordExport.prototype.serializeDocumentBody = function (writer) {
writer.writeStartElement(undefined, 'body', this.wNamespace);
var count = this.document[sectionsProperty[this.keywordIndex]].length;
for (var i = 0; i < count; i++) {
this.section = this.document[sectionsProperty[this.keywordIndex]][parseInt(i.toString(), 10)];
this.lastSection = i === count - 1;
this.containerWidth = this.section[sectionFormatProperty[this.keywordIndex]][pageWidthProperty[this.keywordIndex]] -
(this.section[sectionFormatProperty[this.keywordIndex]][leftMarginProperty[this.keywordIndex]] +
this.section[sectionFormatProperty[this.keywordIndex]][rightMarginProperty[this.keywordIndex]]);
this.serializeSection(writer, this.section, i === count - 1);
this.section = undefined;
}
writer.writeEndElement();
};
// Serializes the Section.
WordExport.prototype.serializeSection = function (writer, section, last) {
this.blockOwner = section;
if (!isNullOrUndefined(section[blocksProperty[this.keywordIndex]])) {
this.serializeBodyItems(writer, section[blocksProperty[this.keywordIndex]], last);
}
if (last) {
this.serializeSectionProperties(writer, section);
}
this.blockOwner = undefined;
};
// Serialize the comments (comments.xml)
WordExport.prototype.serializeComments = function () {
if (this.mComments.length === 0 || (this.mComments.length === 1 && this.mComments[0].text === '')) {
return;
}
var writer = new XmlWriter();
writer.writeStartElement('w', 'comments', this.wNamespace);
this.serializeCommentCommonAttribute(writer);
this.serializeCommentInternal(writer, this.mComments);
writer.writeEndElement();
var zipArchiveItem = new ZipArchiveItem(writer.buffer, this.commentsPath);
this.mArchive.addItem(zipArchiveItem);
};
//SerializeThemes the themes (theme.xml)
WordExport.prototype.serializeThemes = function () {
if (!isNullOrUndefined(this.mThemes)) {
var writer = new XmlWriter();
writer.writeStartElement('a', 'theme', this.aNamespace);
writer.writeAttributeString(undefined, 'name', undefined, 'Office Theme');
writer.writeStartElement(undefined, 'themeElements', this.aNamespace);
writer.writeRaw('<a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000" /></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF" /></a:lt1><a:dk2><a:srgbClr val="44546A" /></a:dk2><a:lt2><a:srgbClr val="E7E6E6" /></a:lt2><a:accent1><a:srgbClr val="4472C4" /></a:accent1><a:accent2><a:srgbClr val="ED7D31" /></a:accent2><a:accent3><a:srgbClr val="A5A5A5" /></a:accent3><a:accent4><a:srgbClr val="FFC000" /></a:accent4><a:accent5><a:srgbClr val="5B9BD5" /></a:accent5><a:accent6><a:srgbClr val="70AD47" /></a:accent6><a:hlink><a:srgbClr val="0563C1" /></a:hlink><a:folHlink><a:srgbClr val="954F72" /></a:folHlink></a:clrScheme>');
writer.writeStartElement(undefined, 'fontScheme', this.aNamespace);
writer.writeAttributeString(undefined, 'name', undefined, this.mThemes[fontSchemeNameProperty[this.keywordIndex]]);
writer.writeStartElement(undefined, 'majorFont', this.aNamespace);
for (var i = 0; i < this.mThemes[fontSchemeProperty[this.keywordIndex]][majorFontSchemeProperty[this.keywordIndex]][fontSchemeListProperty[this.keywordIndex]].length; i++) {
var theme = this.mThemes[fontSchemeProperty[this.keywordIndex]][majorFontSchemeProperty[this.keywordIndex]][fontSchemeListProperty[this.keywordIndex]][parseInt(i.toString(), 10)];
this.themeFont(writer, theme);
}
var keys = Object.keys(this.mThemes[fontSchemeProperty[this.keywordIndex]][majorFontSchemeProperty[this.keywordIndex]][fontTypefaceProperty[this.keywordIndex]]);
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var key = keys_1[_i];
this.themeType(writer, key, this.mThemes[fontSchemeProperty[this.keywordIndex]][majorFontSchemeProperty[this.keywordIndex]][fontTypefaceProperty[this.keywordIndex]]["" + key]);
}
writer.writeEndElement();
writer.writeStartElement(undefined, 'minorFont', this.aNamespace);
for (var i = 0; i < this.mThemes[f