This commit is contained in:
csh 2025-04-16 10:03:34 +08:00
parent 87c3aa75f7
commit f816e8b6e3
20 changed files with 27378 additions and 28116 deletions

View File

@ -1,5 +1,7 @@
# OfficeXml
[迁移指南](./迁移指南.md)
## 概述
将 docx、pptx、xlsx 等文件中的 xml 转为 tsl 对象
@ -50,7 +52,11 @@ echo p.Rs(1).T.Text; // 输出:(份)
## 基类
`OpenXmlElement.tsf`提供了一些常用的方法,具体可见`tsf`文件
`OpenXmlAttribute`是节点的属性类
`OpenXmlElement.tsf`是节点基类
`OpenXmlSimpleType`是简单类型的元素节点类,继承于`OpenXmlElement`,如`<b />`
`OpenXmlTextElement`是包含文本内容的元素节点类,继承于`OpenXmlElement`,如`<t>文本</t>`
`OpenXmlCompositeElement`是复杂节点的元素节点类,继承于`OpenXmlElement`,会包含一系列的属性或其他元素节点类
## Unit 单元
@ -209,7 +215,7 @@ style := styles_adapter.GetStyleByStyleId("a6");
echo style.Name; // 输出的是"页脚 字符"
```
### 补充
### 其他设计的补充
```xml
<m:r>
@ -232,3 +238,8 @@ echo style.Name; // 输出的是"页脚 字符"
由于设计取对象时候不包含前缀,那么同时存在多个`rPr`时,如何区分是哪一个?
取`m:rPr`时,可通过`r.RPr`,这是因为它们的前缀都是`m`,所以可直接获取
取`a:rPr`时,需要指定前缀`a`,通过`r.RPr('a')`,进行获取`RPr`对象
## TODO
- [ ] 命名空间不同,但是名字相同属性的读写访问
- [ ] 属性的删除操作

File diff suppressed because it is too large Load Diff

View File

@ -1184,14 +1184,6 @@ begin
{self.}RsidP := object_.XmlAttrRsidP.Value;
if not ifnil(object_.XmlChildPPr) then
{self.}XmlChildPPr := new PPrUnitDecorator(object_.XmlChildPPr);
if not ifnil(object_.XmlChildOMathPara) then
{self.}XmlChildOMathPara := new OMathParaUnitDecorator(object_.XmlChildOMathPara);
if not ifnil(object_.XmlChildOMath) then
{self.}XmlChildOMath := new OMathUnitDecorator(object_.XmlChildOMath);
if not ifnil(object_.XmlChildIns) then
{self.}XmlChildIns := new InsUnitDecorator(object_.XmlChildIns);
if not ifnil(object_.XmlChildDel) then
{self.}XmlChildDel := new DelUnitDecorator(object_.XmlChildDel);
elems := object_.Sdts();
for _,elem in elems do
{self.}AppendChild(new SdtUnitDecorator(elem));
@ -1216,6 +1208,14 @@ begin
elems := object_.FldSimples();
for _,elem in elems do
{self.}AppendChild(new FldSimpleUnitDecorator(elem));
if not ifnil(object_.XmlChildOMathPara) then
{self.}XmlChildOMathPara := new OMathParaUnitDecorator(object_.XmlChildOMathPara);
if not ifnil(object_.XmlChildOMath) then
{self.}XmlChildOMath := new OMathUnitDecorator(object_.XmlChildOMath);
if not ifnil(object_.XmlChildIns) then
{self.}XmlChildIns := new InsUnitDecorator(object_.XmlChildIns);
if not ifnil(object_.XmlChildDel) then
{self.}XmlChildDel := new DelUnitDecorator(object_.XmlChildDel);
tslassigning := tslassigning_backup;
end;
@ -1340,11 +1340,11 @@ begin
if not ifnil(object_.XmlChildTabs) then
{self.}XmlChildTabs := new TabsUnitDecorator(object_.XmlChildTabs);
if not ifnil(object_.XmlChildBidi) then
{self.}Bidi.Copy(object_.XmlChildBidi);
{self.}XmlChildBidi.Copy(object_.XmlChildBidi);
if not ifnil(object_.XmlChildWidowControl) then
{self.}WidowControl.Copy(object_.XmlChildWidowControl);
{self.}XmlChildWidowControl.Copy(object_.XmlChildWidowControl);
if not ifnil(object_.XmlChildSnapToGrid) then
{self.}SnapToGrid.Copy(object_.XmlChildSnapToGrid);
{self.}XmlChildSnapToGrid.Copy(object_.XmlChildSnapToGrid);
if not ifnil(object_.XmlChildPStyle) then
{self.}XmlChildPStyle := new PureWValUnitDecorator(object_.XmlChildPStyle);
if not ifnil(object_.XmlChildNumPr) then
@ -1354,21 +1354,21 @@ begin
if not ifnil(object_.XmlChildInd) then
{self.}XmlChildInd := new IndUnitDecorator(object_.XmlChildInd);
if not ifnil(object_.XmlChildKeepNext) then
{self.}KeepNext.Copy(object_.XmlChildKeepNext);
{self.}XmlChildKeepNext.Copy(object_.XmlChildKeepNext);
if not ifnil(object_.XmlChildKeepLines) then
{self.}KeepLines.Copy(object_.XmlChildKeepLines);
{self.}XmlChildKeepLines.Copy(object_.XmlChildKeepLines);
if not ifnil(object_.XmlChildMirrorIndents) then
{self.}MirrorIndents.Copy(object_.XmlChildMirrorIndents);
{self.}XmlChildMirrorIndents.Copy(object_.XmlChildMirrorIndents);
if not ifnil(object_.XmlChildKinsoku) then
{self.}XmlChildKinsoku := new PureWValUnitDecorator(object_.XmlChildKinsoku);
if not ifnil(object_.XmlChildPageBreakBefore) then
{self.}PageBreakBefore.Copy(object_.XmlChildPageBreakBefore);
{self.}XmlChildPageBreakBefore.Copy(object_.XmlChildPageBreakBefore);
if not ifnil(object_.XmlChildSuppressAutoHyphens) then
{self.}SuppressAutoHyphens.Copy(object_.XmlChildSuppressAutoHyphens);
{self.}XmlChildSuppressAutoHyphens.Copy(object_.XmlChildSuppressAutoHyphens);
if not ifnil(object_.XmlChildSuppressLineNumbers) then
{self.}SuppressLineNumbers.Copy(object_.XmlChildSuppressLineNumbers);
{self.}XmlChildSuppressLineNumbers.Copy(object_.XmlChildSuppressLineNumbers);
if not ifnil(object_.XmlChildSuppressOverlap) then
{self.}SuppressOverlap.Copy(object_.XmlChildSuppressOverlap);
{self.}XmlChildSuppressOverlap.Copy(object_.XmlChildSuppressOverlap);
if not ifnil(object_.XmlChildOverflowPunct) then
{self.}XmlChildOverflowPunct := new PureWValUnitDecorator(object_.XmlChildOverflowPunct);
if not ifnil(object_.XmlChildAdjustRightInd) then
@ -1386,7 +1386,7 @@ begin
if not ifnil(object_.XmlChildPBdr) then
{self.}XmlChildPBdr := new PBdrUnitDecorator(object_.XmlChildPBdr);
if not ifnil(object_.XmlChildContextualSpacing) then
{self.}ContextualSpacing.Copy(object_.XmlChildContextualSpacing);
{self.}XmlChildContextualSpacing.Copy(object_.XmlChildContextualSpacing);
if not ifnil(object_.XmlChildShd) then
{self.}XmlChildShd := new ShdUnitDecorator(object_.XmlChildShd);
if not ifnil(object_.XmlChildWordWrap) then
@ -1698,13 +1698,13 @@ begin
if not ifnil(object_.XmlChildKern) then
{self.}XmlChildKern := new PureWValUnitDecorator(object_.XmlChildKern);
if not ifnil(object_.XmlChildI) then
{self.}I.Copy(object_.XmlChildI);
{self.}XmlChildI.Copy(object_.XmlChildI);
if not ifnil(object_.XmlChildICs) then
{self.}ICs.Copy(object_.XmlChildICs);
{self.}XmlChildICs.Copy(object_.XmlChildICs);
if not ifnil(object_.XmlChildB) then
{self.}B.Copy(object_.XmlChildB);
{self.}XmlChildB.Copy(object_.XmlChildB);
if not ifnil(object_.XmlChildBCs) then
{self.}BCs.Copy(object_.XmlChildBCs);
{self.}XmlChildBCs.Copy(object_.XmlChildBCs);
if not ifnil(object_.XmlChildBdr) then
{self.}XmlChildBdr := new BdrUnitDecorator(object_.XmlChildBdr);
if not ifnil(object_.XmlChildCaps) then
@ -1712,7 +1712,7 @@ begin
if not ifnil(object_.XmlChildDel) then
{self.}XmlChildDel := new DelUnitDecorator(object_.XmlChildDel);
if not ifnil(object_.XmlChildStrike) then
{self.}Strike.Copy(object_.XmlChildStrike);
{self.}XmlChildStrike.Copy(object_.XmlChildStrike);
if not ifnil(object_.XmlChildDStrike) then
{self.}XmlChildDStrike := new PureWValUnitDecorator(object_.XmlChildDStrike);
if not ifnil(object_.XmlChildEffect) then
@ -1730,13 +1730,13 @@ begin
if not ifnil(object_.XmlChildEastAsianLayout) then
{self.}XmlChildEastAsianLayout := new EastAsianLayoutUnitDecorator(object_.XmlChildEastAsianLayout);
if not ifnil(object_.XmlChildCs) then
{self.}Cs.Copy(object_.XmlChildCs);
{self.}XmlChildCs.Copy(object_.XmlChildCs);
if not ifnil(object_.XmlChildSz) then
{self.}XmlChildSz := new SzUnitDecorator(object_.XmlChildSz);
if not ifnil(object_.XmlChildSzCs) then
{self.}XmlChildSzCs := new SzCsUnitDecorator(object_.XmlChildSzCs);
if not ifnil(object_.XmlChildU) then
{self.}U.Copy(object_.XmlChildU);
{self.}XmlChildU.Copy(object_.XmlChildU);
if not ifnil(object_.XmlChildLang) then
{self.}XmlChildLang := new LangUnitDecorator(object_.XmlChildLang);
if not ifnil(object_.XmlChildImprint) then
@ -1748,13 +1748,13 @@ begin
if not ifnil(object_.XmlChildRtl) then
{self.}XmlChildRtl := new PureWValUnitDecorator(object_.XmlChildRtl);
if not ifnil(object_.XmlChildOMath) then
{self.}OMath.Copy(object_.XmlChildOMath);
{self.}XmlChildOMath.Copy(object_.XmlChildOMath);
if not ifnil(object_.XmlChildShadow) then
{self.}Shadow.Copy(object_.XmlChildShadow);
{self.}XmlChildShadow.Copy(object_.XmlChildShadow);
if not ifnil(object_.XmlChildSpecVanish) then
{self.}SpecVanish.Copy(object_.XmlChildSpecVanish);
{self.}XmlChildSpecVanish.Copy(object_.XmlChildSpecVanish);
if not ifnil(object_.XmlChildVanish) then
{self.}Vanish.Copy(object_.XmlChildVanish);
{self.}XmlChildVanish.Copy(object_.XmlChildVanish);
if not ifnil(object_.XmlChildShd) then
{self.}XmlChildShd := new ShdUnitDecorator(object_.XmlChildShd);
if not ifnil(object_.XmlChildSmallCaps) then
@ -2133,8 +2133,8 @@ function RUnitDecorator.Convert();
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
if not ifnil(object_.XmlAttrWRsidRPr) then
{self.}WRsidRPr := object_.XmlAttrWRsidRPr.Value;
if not ifnil(object_.XmlAttrRsidRPr) then
{self.}RsidRPr := object_.XmlAttrRsidRPr.Value;
if not ifnil(object_.XmlAttrAnchor) then
{self.}Anchor := object_.XmlAttrAnchor.Value;
if not ifnil(object_.XmlAttrHistory) then
@ -2151,11 +2151,11 @@ begin
if not ifnil(object_.XmlChildInstrText) then
{self.}XmlChildInstrText := new InstrTextUnitDecorator(object_.XmlChildInstrText);
if not ifnil(object_.XmlChildSeparator) then
{self.}Separator.Copy(object_.XmlChildSeparator);
{self.}XmlChildSeparator.Copy(object_.XmlChildSeparator);
if not ifnil(object_.XmlChildContinuationSeparator) then
{self.}ContinuationSeparator.Copy(object_.XmlChildContinuationSeparator);
{self.}XmlChildContinuationSeparator.Copy(object_.XmlChildContinuationSeparator);
if not ifnil(object_.XmlChildLastRenderedPageBreak) then
{self.}LastRenderedPageBreak.Copy(object_.XmlChildLastRenderedPageBreak);
{self.}XmlChildLastRenderedPageBreak.Copy(object_.XmlChildLastRenderedPageBreak);
if not ifnil(object_.XmlChildAlternateContent) then
{self.}XmlChildAlternateContent := new AlternateContentUnitDecorator(object_.XmlChildAlternateContent);
if not ifnil(object_.XmlChildDrawing) then
@ -2169,7 +2169,7 @@ begin
if not ifnil(object_.XmlChildFootnoteReference) then
{self.}XmlChildFootnoteReference := new FootnoteReferenceUnitDecorator(object_.XmlChildFootnoteReference);
if not ifnil(object_.XmlChildFootnoteRef) then
{self.}FootnoteRef.Copy(object_.XmlChildFootnoteRef);
{self.}XmlChildFootnoteRef.Copy(object_.XmlChildFootnoteRef);
tslassigning := tslassigning_backup;
end;
@ -2697,7 +2697,7 @@ begin
if not ifnil(object_.XmlChildJc) then
{self.}XmlChildJc := new PureWValUnitDecorator(object_.XmlChildJc);
if not ifnil(object_.XmlChildCantSplit) then
{self.}CantSplit.Copy(object_.XmlChildCantSplit);
{self.}XmlChildCantSplit.Copy(object_.XmlChildCantSplit);
if not ifnil(object_.XmlChildCnfStyle) then
{self.}XmlChildCnfStyle := new CnfStyleUnitDecorator(object_.XmlChildCnfStyle);
if not ifnil(object_.XmlChildIns) then
@ -2853,11 +2853,11 @@ begin
if not ifnil(object_.XmlChildGridSpan) then
{self.}XmlChildGridSpan := new GridSpanUnitDecorator(object_.XmlChildGridSpan);
if not ifnil(object_.XmlChildVMerge) then
{self.}VMerge.Copy(object_.XmlChildVMerge);
{self.}XmlChildVMerge.Copy(object_.XmlChildVMerge);
if not ifnil(object_.XmlChildVAlign) then
{self.}XmlChildVAlign := new PureWValUnitDecorator(object_.XmlChildVAlign);
if not ifnil(object_.XmlChildHideMark) then
{self.}HideMark.Copy(object_.XmlChildHideMark);
{self.}XmlChildHideMark.Copy(object_.XmlChildHideMark);
if not ifnil(object_.XmlChildShd) then
{self.}XmlChildShd := new ShdUnitDecorator(object_.XmlChildShd);
if not ifnil(object_.XmlChildTcBorders) then
@ -3116,7 +3116,7 @@ begin
if not ifnil(object_.XmlChildCols) then
{self.}XmlChildCols := new ColsUnitDecorator(object_.XmlChildCols);
if not ifnil(object_.XmlChildTitlePg) then
{self.}TitlePg.Copy(object_.XmlChildTitlePg);
{self.}XmlChildTitlePg.Copy(object_.XmlChildTitlePg);
if not ifnil(object_.XmlChildDocGrid) then
{self.}XmlChildDocGrid := new DocGridUnitDecorator(object_.XmlChildDocGrid);
if not ifnil(object_.XmlChildTextDirection) then
@ -3511,13 +3511,13 @@ begin
if not ifnil(object_.XmlChildZoom) then
{self.}XmlChildZoom := new ZoomUnitDecorator(object_.XmlChildZoom);
if not ifnil(object_.XmlChildBordersDoNotSurroundHeader) then
{self.}BordersDoNotSurroundHeader.Copy(object_.XmlChildBordersDoNotSurroundHeader);
{self.}XmlChildBordersDoNotSurroundHeader.Copy(object_.XmlChildBordersDoNotSurroundHeader);
if not ifnil(object_.XmlChildBordersDoNotSurroundFooter) then
{self.}BordersDoNotSurroundFooter.Copy(object_.XmlChildBordersDoNotSurroundFooter);
{self.}XmlChildBordersDoNotSurroundFooter.Copy(object_.XmlChildBordersDoNotSurroundFooter);
if not ifnil(object_.XmlChildDefaultTabStop) then
{self.}XmlChildDefaultTabStop := new PureWValUnitDecorator(object_.XmlChildDefaultTabStop);
if not ifnil(object_.XmlChildEvenAndOddHeaders) then
{self.}EvenAndOddHeaders.Copy(object_.XmlChildEvenAndOddHeaders);
{self.}XmlChildEvenAndOddHeaders.Copy(object_.XmlChildEvenAndOddHeaders);
if not ifnil(object_.XmlChildDrawingGridVerticalSpacing) then
{self.}XmlChildDrawingGridVerticalSpacing := new PureWValUnitDecorator(object_.XmlChildDrawingGridVerticalSpacing);
if not ifnil(object_.XmlChildDisplayHorizontalDrawingGridEvery) then
@ -3543,7 +3543,7 @@ begin
if not ifnil(object_.XmlChildClrSchemeMapping) then
{self.}XmlChildClrSchemeMapping := new ClrSchemeMappingUnitDecorator(object_.XmlChildClrSchemeMapping);
if not ifnil(object_.XmlChildDoNotIncludeSubdocsInStats) then
{self.}DoNotIncludeSubdocsInStats.Copy(object_.XmlChildDoNotIncludeSubdocsInStats);
{self.}XmlChildDoNotIncludeSubdocsInStats.Copy(object_.XmlChildDoNotIncludeSubdocsInStats);
if not ifnil(object_.XmlChildShapeDefaults) then
{self.}XmlChildShapeDefaults := new ShapeDefaults2UnitDecorator(object_.XmlChildShapeDefaults);
if not ifnil(object_.XmlChildDecimalSymbol) then
@ -3557,7 +3557,7 @@ begin
if not ifnil(object_.XmlChildDocId) then
{self.}XmlChildDocId := new PureWValUnitDecorator(object_.XmlChildDocId);
if not ifnil(object_.XmlChildChartTrackingRefBased) then
{self.}ChartTrackingRefBased.Copy(object_.XmlChildChartTrackingRefBased);
{self.}XmlChildChartTrackingRefBased.Copy(object_.XmlChildChartTrackingRefBased);
tslassigning := tslassigning_backup;
end;
@ -3703,19 +3703,19 @@ begin
tslassigning_backup := tslassigning;
tslassigning := 1;
if not ifnil(object_.XmlChildSpaceForUL) then
{self.}SpaceForUL.Copy(object_.XmlChildSpaceForUL);
{self.}XmlChildSpaceForUL.Copy(object_.XmlChildSpaceForUL);
if not ifnil(object_.XmlChildBalanceSingleByteDoubleByteWidth) then
{self.}BalanceSingleByteDoubleByteWidth.Copy(object_.XmlChildBalanceSingleByteDoubleByteWidth);
{self.}XmlChildBalanceSingleByteDoubleByteWidth.Copy(object_.XmlChildBalanceSingleByteDoubleByteWidth);
if not ifnil(object_.XmlChildDoNotLeaveBackslashAlone) then
{self.}DoNotLeaveBackslashAlone.Copy(object_.XmlChildDoNotLeaveBackslashAlone);
{self.}XmlChildDoNotLeaveBackslashAlone.Copy(object_.XmlChildDoNotLeaveBackslashAlone);
if not ifnil(object_.XmlChildUlTrailSpace) then
{self.}UlTrailSpace.Copy(object_.XmlChildUlTrailSpace);
{self.}XmlChildUlTrailSpace.Copy(object_.XmlChildUlTrailSpace);
if not ifnil(object_.XmlChildDoNotExpandShiftReturn) then
{self.}DoNotExpandShiftReturn.Copy(object_.XmlChildDoNotExpandShiftReturn);
{self.}XmlChildDoNotExpandShiftReturn.Copy(object_.XmlChildDoNotExpandShiftReturn);
if not ifnil(object_.XmlChildAdjustLineHeightInTable) then
{self.}AdjustLineHeightInTable.Copy(object_.XmlChildAdjustLineHeightInTable);
{self.}XmlChildAdjustLineHeightInTable.Copy(object_.XmlChildAdjustLineHeightInTable);
if not ifnil(object_.XmlChildUseFELayout) then
{self.}UseFELayout.Copy(object_.XmlChildUseFELayout);
{self.}XmlChildUseFELayout.Copy(object_.XmlChildUseFELayout);
elems := object_.CompatSettings();
for _,elem in elems do
{self.}AppendChild(new CompatSettingUnitDecorator(elem));
@ -4097,11 +4097,11 @@ begin
if not ifnil(object_.XmlChildUIPriority) then
{self.}XmlChildUIPriority := new PureWValUnitDecorator(object_.XmlChildUIPriority);
if not ifnil(object_.XmlChildSemiHidden) then
{self.}SemiHidden.Copy(object_.XmlChildSemiHidden);
{self.}XmlChildSemiHidden.Copy(object_.XmlChildSemiHidden);
if not ifnil(object_.XmlChildUnhideWhenUsed) then
{self.}UnhideWhenUsed.Copy(object_.XmlChildUnhideWhenUsed);
{self.}XmlChildUnhideWhenUsed.Copy(object_.XmlChildUnhideWhenUsed);
if not ifnil(object_.XmlChildQFormat) then
{self.}QFormat.Copy(object_.XmlChildQFormat);
{self.}XmlChildQFormat.Copy(object_.XmlChildQFormat);
if not ifnil(object_.XmlChildRsid) then
{self.}XmlChildRsid := new PureWValUnitDecorator(object_.XmlChildRsid);
if not ifnil(object_.XmlChildPPr) then
@ -4220,9 +4220,9 @@ begin
if not ifnil(object_.XmlAttrIgnorable) then
{self.}Ignorable := object_.XmlAttrIgnorable.Value;
if not ifnil(object_.XmlChildOptimizeForBrowser) then
{self.}OptimizeForBrowser.Copy(object_.XmlChildOptimizeForBrowser);
{self.}XmlChildOptimizeForBrowser.Copy(object_.XmlChildOptimizeForBrowser);
if not ifnil(object_.XmlChildAllowPNG) then
{self.}AllowPNG.Copy(object_.XmlChildAllowPNG);
{self.}XmlChildAllowPNG.Copy(object_.XmlChildAllowPNG);
tslassigning := tslassigning_backup;
end;

File diff suppressed because it is too large Load Diff

View File

@ -862,9 +862,9 @@ begin
if not ifnil(object_.XmlChildThemeElements) then
{self.}XmlChildThemeElements := new ThemeElementsUnitDecorator(object_.XmlChildThemeElements);
if not ifnil(object_.XmlChildObjectDefaults) then
{self.}ObjectDefaults.Copy(object_.XmlChildObjectDefaults);
{self.}XmlChildObjectDefaults.Copy(object_.XmlChildObjectDefaults);
if not ifnil(object_.XmlChildExtraClrSchemeLst) then
{self.}ExtraClrSchemeLst.Copy(object_.XmlChildExtraClrSchemeLst);
{self.}XmlChildExtraClrSchemeLst.Copy(object_.XmlChildExtraClrSchemeLst);
if not ifnil(object_.XmlChildExtLst) then
{self.}XmlChildExtLst := new ExtLstUnitDecorator(object_.XmlChildExtLst);
tslassigning := tslassigning_backup;
@ -1623,7 +1623,7 @@ begin
if not ifnil(object_.XmlChildLegendPos) then
{self.}XmlChildLegendPos := new PureValUnitDecorator(object_.XmlChildLegendPos);
if not ifnil(object_.XmlChildLayout) then
{self.}Layout.Copy(object_.XmlChildLayout);
{self.}XmlChildLayout.Copy(object_.XmlChildLayout);
if not ifnil(object_.XmlChildOverlay) then
{self.}XmlChildOverlay := new PureValUnitDecorator(object_.XmlChildOverlay);
if not ifnil(object_.XmlChildTxPr) then
@ -1673,7 +1673,7 @@ begin
tslassigning_backup := tslassigning;
tslassigning := 1;
if not ifnil(object_.XmlChildLayout) then
{self.}Layout.Copy(object_.XmlChildLayout);
{self.}XmlChildLayout.Copy(object_.XmlChildLayout);
if not ifnil(object_.XmlChildBarChart) then
{self.}XmlChildBarChart := new BarChartUnitDecorator(object_.XmlChildBarChart);
if not ifnil(object_.XmlChildCatAx) then
@ -1709,11 +1709,11 @@ begin
{self.}XmlChildGrouping := new PureValUnitDecorator(object_.XmlChildGrouping);
if not ifnil(object_.XmlChildVaryColors) then
{self.}XmlChildVaryColors := new PureValUnitDecorator(object_.XmlChildVaryColors);
if not ifnil(object_.XmlChildGapWidth) then
{self.}XmlChildGapWidth := new PureValUnitDecorator(object_.XmlChildGapWidth);
elems := object_.Sers();
for _,elem in elems do
{self.}AppendChild(new SerUnitDecorator(elem));
if not ifnil(object_.XmlChildGapWidth) then
{self.}XmlChildGapWidth := new PureValUnitDecorator(object_.XmlChildGapWidth);
elems := object_.AxIds();
for _,elem in elems do
{self.}AppendChild(new PureValUnitDecorator(elem));
@ -2094,7 +2094,7 @@ begin
if not ifnil(object_.XmlChildBodyPr) then
{self.}XmlChildBodyPr := new BodyPrUnitDecorator(object_.XmlChildBodyPr);
if not ifnil(object_.XmlChildLstStyle) then
{self.}LstStyle.Copy(object_.XmlChildLstStyle);
{self.}XmlChildLstStyle.Copy(object_.XmlChildLstStyle);
elems := object_.Ps();
for _,elem in elems do
{self.}AppendChild(new PUnitDecorator(elem));
@ -2120,7 +2120,7 @@ begin
if not ifnil(object_.XmlChildTx) then
{self.}XmlChildTx := new TxUnitDecorator(object_.XmlChildTx);
if not ifnil(object_.XmlChildLayout) then
{self.}Layout.Copy(object_.XmlChildLayout);
{self.}XmlChildLayout.Copy(object_.XmlChildLayout);
if not ifnil(object_.XmlChildOverlay) then
{self.}XmlChildOverlay := new PureValUnitDecorator(object_.XmlChildOverlay);
tslassigning := tslassigning_backup;
@ -2168,7 +2168,7 @@ begin
if not ifnil(object_.XmlChildBodyPr) then
{self.}XmlChildBodyPr := new BodyPrUnitDecorator(object_.XmlChildBodyPr);
if not ifnil(object_.XmlChildLstStyle) then
{self.}LstStyle.Copy(object_.XmlChildLstStyle);
{self.}XmlChildLstStyle.Copy(object_.XmlChildLstStyle);
elems := object_.Ps();
for _,elem in elems do
{self.}AppendChild(new PUnitDecorator(elem));
@ -2230,7 +2230,7 @@ begin
if not ifnil(object_.XmlChildPrstTxWrap) then
{self.}XmlChildPrstTxWrap := new PrstTxWrapUnitDecorator(object_.XmlChildPrstTxWrap);
if not ifnil(object_.XmlChildNoAutofit) then
{self.}NoAutofit.Copy(object_.XmlChildNoAutofit);
{self.}XmlChildNoAutofit.Copy(object_.XmlChildNoAutofit);
tslassigning := tslassigning_backup;
end;
@ -2253,7 +2253,7 @@ begin
if not ifnil(object_.XmlAttrPrst) then
{self.}Prst := object_.XmlAttrPrst.Value;
if not ifnil(object_.XmlChildAvLst) then
{self.}AvLst.Copy(object_.XmlChildAvLst);
{self.}XmlChildAvLst.Copy(object_.XmlChildAvLst);
tslassigning := tslassigning_backup;
end;
@ -2952,7 +2952,7 @@ begin
if not ifnil(object_.XmlChildPrstGeom) then
{self.}XmlChildPrstGeom := new PrstGeomUnitDecorator(object_.XmlChildPrstGeom);
if not ifnil(object_.XmlChildNoFill) then
{self.}NoFill.Copy(object_.XmlChildNoFill);
{self.}XmlChildNoFill.Copy(object_.XmlChildNoFill);
if not ifnil(object_.XmlChildSolidFill) then
{self.}XmlChildSolidFill := new SolidFillUnitDecorator(object_.XmlChildSolidFill);
if not ifnil(object_.XmlChildLn) then
@ -3008,7 +3008,7 @@ begin
if not ifnil(object_.XmlAttrAlgn) then
{self.}Algn := object_.XmlAttrAlgn.Value;
if not ifnil(object_.XmlChildNoFill) then
{self.}NoFill.Copy(object_.XmlChildNoFill);
{self.}XmlChildNoFill.Copy(object_.XmlChildNoFill);
if not ifnil(object_.XmlChildSolidFill) then
{self.}XmlChildSolidFill := new SolidFillUnitDecorator(object_.XmlChildSolidFill);
if not ifnil(object_.XmlChildPrstDash) then
@ -3016,9 +3016,9 @@ begin
if not ifnil(object_.XmlChildMiter) then
{self.}XmlChildMiter := new MiterUnitDecorator(object_.XmlChildMiter);
if not ifnil(object_.XmlChildHeadEnd) then
{self.}HeadEnd.Copy(object_.XmlChildHeadEnd);
{self.}XmlChildHeadEnd.Copy(object_.XmlChildHeadEnd);
if not ifnil(object_.XmlChildTailEnd) then
{self.}TailEnd.Copy(object_.XmlChildTailEnd);
{self.}XmlChildTailEnd.Copy(object_.XmlChildTailEnd);
tslassigning := tslassigning_backup;
end;
@ -3194,7 +3194,7 @@ begin
if not ifnil(object_.XmlChildEffectExtent) then
{self.}XmlChildEffectExtent := new EffectExtentUnitDecorator(object_.XmlChildEffectExtent);
if not ifnil(object_.XmlChildWrapNone) then
{self.}WrapNone.Copy(object_.XmlChildWrapNone);
{self.}XmlChildWrapNone.Copy(object_.XmlChildWrapNone);
if not ifnil(object_.XmlChildDocPr) then
{self.}XmlChildDocPr := new DocPrUnitDecorator(object_.XmlChildDocPr);
if not ifnil(object_.XmlChildCNvGraphicFramePr) then

122
autounit/PptxML.tsf Normal file
View File

@ -0,0 +1,122 @@
unit PptxML;
interface
type SldLayoutId = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
function Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
function Init();override;
function Copy(_obj: SldLayoutId);override;
public
// attributes property
property Id read ReadXmlAttrId write WriteXmlAttrId;
property Id read ReadXmlAttrId write WriteXmlAttrId;
property Id read ReadXmlAttrId write WriteXmlAttrId;
function ReadXmlAttrId();
function WriteXmlAttrId(_value);
function ReadXmlAttrId();
function WriteXmlAttrId(_value);
function ReadXmlAttrId();
function WriteXmlAttrId(_value);
public
// Attributes
XmlAttrId: OpenXmlAttribute;
XmlAttrId: OpenXmlAttribute;
XmlAttrId: OpenXmlAttribute;
end;
implementation
function SldLayoutId.Create();overload;
begin
{self.}Create(nil, "p", "sldLayoutId");
end;
function SldLayoutId.Create(_node: XmlNode);overload;
begin
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function SldLayoutId.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function SldLayoutId.Init();override;
begin
pre := {self.}Prefix ? {self.}Prefix + ":" : "";
attributes_ := array();
attributes_pf_ := array(
pre + "id": makeweakref(thisFunction(WriteXmlAttrId)),
"id": makeweakref(thisFunction(WriteXmlAttrId)),
"r:id": makeweakref(thisFunction(WriteXmlAttrId)),
);
sorted_child_ := array(
);
container_ := new TSOfficeContainer(sorted_child_);
end;
function SldLayoutId.Copy(_obj: SldLayoutId);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Id) then
{self.}Id := _obj.Id;
if not ifnil(_obj.Id) then
{self.}Id := _obj.Id;
if not ifnil(_obj.Id) then
{self.}Id := _obj.Id;
tslassigning := tslassigning_backup;
end;
function SldLayoutId.ReadXmlAttrId();
begin
return {self.}XmlAttrId.Value;
end;
function SldLayoutId.WriteXmlAttrId(_value);
begin
if ifnil({self.}XmlAttrId) then
begin
{self.}XmlAttrId := new OpenXmlAttribute({self.}Prefix, "id", nil);
attributes_[length(attributes_)] := {self.}XmlAttrId;
end
{self.}XmlAttrId.Value := _value;
end;
function SldLayoutId.ReadXmlAttrId();
begin
return {self.}XmlAttrId.Value;
end;
function SldLayoutId.WriteXmlAttrId(_value);
begin
if ifnil({self.}XmlAttrId) then
begin
{self.}XmlAttrId := new OpenXmlAttribute("", "id", nil);
attributes_[length(attributes_)] := {self.}XmlAttrId;
end
{self.}XmlAttrId.Value := _value;
end;
function SldLayoutId.ReadXmlAttrId();
begin
return {self.}XmlAttrId.Value;
end;
function SldLayoutId.WriteXmlAttrId(_value);
begin
if ifnil({self.}XmlAttrId) then
begin
{self.}XmlAttrId := new OpenXmlAttribute("r", "id", nil);
attributes_[length(attributes_)] := {self.}XmlAttrId;
end
{self.}XmlAttrId.Value := _value;
end;
end.

View File

@ -0,0 +1,6 @@
unit PptxMLAdapter;
interface
implementation
end.

File diff suppressed because it is too large Load Diff

View File

@ -371,7 +371,7 @@ begin
if not ifnil(object_.XmlChildSmallFrac) then
{self.}XmlChildSmallFrac := new PureMValUnitDecorator(object_.XmlChildSmallFrac);
if not ifnil(object_.XmlChildDispDef) then
{self.}DispDef.Copy(object_.XmlChildDispDef);
{self.}XmlChildDispDef.Copy(object_.XmlChildDispDef);
if not ifnil(object_.XmlChildLMargin) then
{self.}XmlChildLMargin := new PureMValUnitDecorator(object_.XmlChildLMargin);
if not ifnil(object_.XmlChildRMargin) then
@ -474,14 +474,18 @@ begin
elems := object_.Ds();
for _,elem in elems do
{self.}AppendChild(new DUnitDecorator(elem));
if not ifnil(object_.XmlChildF) then
{self.}XmlChildF := new FUnitDecorator(object_.XmlChildF);
if not ifnil(object_.XmlChildRad) then
{self.}XmlChildRad := new RadUnitDecorator(object_.XmlChildRad);
if not ifnil(object_.XmlChildSSub) then
{self.}XmlChildSSub := new SSubUnitDecorator(object_.XmlChildSSub);
if not ifnil(object_.XmlChildNary) then
{self.}XmlChildNary := new NaryUnitDecorator(object_.XmlChildNary);
elems := object_.Fs();
for _,elem in elems do
{self.}AppendChild(new FUnitDecorator(elem));
elems := object_.Rads();
for _,elem in elems do
{self.}AppendChild(new RadUnitDecorator(elem));
elems := object_.SSubs();
for _,elem in elems do
{self.}AppendChild(new SSubUnitDecorator(elem));
elems := object_.Naries();
for _,elem in elems do
{self.}AppendChild(new NaryUnitDecorator(elem));
tslassigning := tslassigning_backup;
end;

View File

@ -2,7 +2,7 @@ unit VML;
interface
uses DocxML;
type Shapetype = class(OpenXmlElement)
type Shapetype = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -74,7 +74,7 @@ public
XmlChildLock: Lock;
end;
type Formulas = class(OpenXmlElement)
type Formulas = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -93,7 +93,7 @@ public
// Children
end;
type Lock = class(OpenXmlElement)
type Lock = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -116,7 +116,7 @@ public
end;
type F = class(OpenXmlElement)
type F = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -135,7 +135,7 @@ public
end;
type Stroke = class(OpenXmlElement)
type Stroke = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -154,7 +154,7 @@ public
end;
type Path = class(OpenXmlElement)
type Path = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -193,7 +193,7 @@ public
end;
type Textpath = class(OpenXmlElement)
type Textpath = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -224,7 +224,7 @@ public
end;
type Handles = class(OpenXmlElement)
type Handles = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -242,7 +242,7 @@ public
XmlChildH: H;
end;
type H = class(OpenXmlElement)
type H = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -265,7 +265,7 @@ public
end;
type Shape = class(OpenXmlElement)
type Shape = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -338,7 +338,7 @@ public
XmlChildWrap: Wrap;
end;
type Wrap = class(OpenXmlElement)
type Wrap = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -361,7 +361,7 @@ public
end;
type Fill = class(OpenXmlElement)
type Fill = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -380,7 +380,7 @@ public
end;
type Imagedata = class(OpenXmlElement)
type Imagedata = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -403,7 +403,7 @@ public
end;
type Textbox = class(OpenXmlElement)
type Textbox = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -421,7 +421,7 @@ public
XmlChildTxbxContent: TxbxContent;
end;
type OLEObject = class(OpenXmlElement)
type OLEObject = class(OpenXmlCompositeElement)
public
function Create();overload;
function Create(_node: XmlNode);overload;
@ -469,13 +469,13 @@ end;
function Shapetype.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Shapetype.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Shapetype.Init();override;
@ -508,7 +508,7 @@ function Shapetype.Copy(_obj: Shapetype);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.AnchorId) then
{self.}AnchorId := _obj.AnchorId;
if not ifnil(_obj.Id) then
@ -679,7 +679,7 @@ end;
function Shapetype.ReadXmlChildStroke(): Stroke;
begin
if tslassigning and ifnil({self.}XmlChildStroke) then
if tslassigning and (ifnil({self.}XmlChildStroke) or {self.}XmlChildStroke.Removed) then
begin
{self.}XmlChildStroke := new Stroke(self, {self.}Prefix, "stroke");
container_.Set({self.}XmlChildStroke);
@ -689,7 +689,7 @@ end;
function Shapetype.ReadXmlChildFormulas(): formulas;
begin
if tslassigning and ifnil({self.}XmlChildFormulas) then
if tslassigning and (ifnil({self.}XmlChildFormulas) or {self.}XmlChildFormulas.Removed) then
begin
{self.}XmlChildFormulas := new formulas(self, {self.}Prefix, "formulas");
container_.Set({self.}XmlChildFormulas);
@ -699,7 +699,7 @@ end;
function Shapetype.ReadXmlChildPath(): Path;
begin
if tslassigning and ifnil({self.}XmlChildPath) then
if tslassigning and (ifnil({self.}XmlChildPath) or {self.}XmlChildPath.Removed) then
begin
{self.}XmlChildPath := new Path(self, {self.}Prefix, "path");
container_.Set({self.}XmlChildPath);
@ -709,7 +709,7 @@ end;
function Shapetype.ReadXmlChildTextpath(): Textpath;
begin
if tslassigning and ifnil({self.}XmlChildTextpath) then
if tslassigning and (ifnil({self.}XmlChildTextpath) or {self.}XmlChildTextpath.Removed) then
begin
{self.}XmlChildTextpath := new Textpath(self, {self.}Prefix, "textpath");
container_.Set({self.}XmlChildTextpath);
@ -719,7 +719,7 @@ end;
function Shapetype.ReadXmlChildHandles(): Handles;
begin
if tslassigning and ifnil({self.}XmlChildHandles) then
if tslassigning and (ifnil({self.}XmlChildHandles) or {self.}XmlChildHandles.Removed) then
begin
{self.}XmlChildHandles := new Handles(self, {self.}Prefix, "handles");
container_.Set({self.}XmlChildHandles);
@ -729,7 +729,7 @@ end;
function Shapetype.ReadXmlChildLock(): Lock;
begin
if tslassigning and ifnil({self.}XmlChildLock) then
if tslassigning and (ifnil({self.}XmlChildLock) or {self.}XmlChildLock.Removed) then
begin
{self.}XmlChildLock := new Lock(self, "o", "lock");
container_.Set({self.}XmlChildLock);
@ -744,13 +744,13 @@ end;
function Formulas.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Formulas.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Formulas.Init();override;
@ -769,7 +769,7 @@ function Formulas.Copy(_obj: Formulas);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
tslassigning := tslassigning_backup;
end;
@ -801,13 +801,13 @@ end;
function Lock.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Lock.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Lock.Init();override;
@ -827,7 +827,7 @@ function Lock.Copy(_obj: Lock);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Ext) then
{self.}Ext := _obj.Ext;
if not ifnil(_obj.Aspectration) then
@ -872,13 +872,13 @@ end;
function F.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function F.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function F.Init();override;
@ -897,7 +897,7 @@ function F.Copy(_obj: F);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Eqn) then
{self.}Eqn := _obj.Eqn;
tslassigning := tslassigning_backup;
@ -925,13 +925,13 @@ end;
function Stroke.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Stroke.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Stroke.Init();override;
@ -950,7 +950,7 @@ function Stroke.Copy(_obj: Stroke);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Joinstyle) then
{self.}Joinstyle := _obj.Joinstyle;
tslassigning := tslassigning_backup;
@ -978,13 +978,13 @@ end;
function Path.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Path.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Path.Init();override;
@ -1008,7 +1008,7 @@ function Path.Copy(_obj: Path);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Extrusionok) then
{self.}Extrusionok := _obj.Extrusionok;
if not ifnil(_obj.Textpathok) then
@ -1121,13 +1121,13 @@ end;
function Textpath.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Textpath.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Textpath.Init();override;
@ -1149,7 +1149,7 @@ function Textpath.Copy(_obj: Textpath);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj._On) then
{self.}_On := _obj._On;
if not ifnil(_obj.Fitshape) then
@ -1228,13 +1228,13 @@ end;
function Handles.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Handles.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Handles.Init();override;
@ -1253,7 +1253,7 @@ function Handles.Copy(_obj: Handles);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.XmlChildH) then
{self.}H.Copy(_obj.XmlChildH);
tslassigning := tslassigning_backup;
@ -1261,7 +1261,7 @@ end;
function Handles.ReadXmlChildH(): H;
begin
if tslassigning and ifnil({self.}XmlChildH) then
if tslassigning and (ifnil({self.}XmlChildH) or {self.}XmlChildH.Removed) then
begin
{self.}XmlChildH := new H(self, {self.}Prefix, "h");
container_.Set({self.}XmlChildH);
@ -1276,13 +1276,13 @@ end;
function H.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function H.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function H.Init();override;
@ -1302,7 +1302,7 @@ function H.Copy(_obj: H);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Xrange) then
{self.}Xrange := _obj.Xrange;
if not ifnil(_obj.Position) then
@ -1347,13 +1347,13 @@ end;
function Shape.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Shape.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Shape.Init();override;
@ -1386,7 +1386,7 @@ function Shape.Copy(_obj: Shape);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Id) then
{self.}Id := _obj.Id;
if not ifnil(_obj.Style) then
@ -1572,7 +1572,7 @@ end;
function Shape.ReadXmlChildFill(): Fill;
begin
if tslassigning and ifnil({self.}XmlChildFill) then
if tslassigning and (ifnil({self.}XmlChildFill) or {self.}XmlChildFill.Removed) then
begin
{self.}XmlChildFill := new Fill(self, {self.}Prefix, "fill");
container_.Set({self.}XmlChildFill);
@ -1582,7 +1582,7 @@ end;
function Shape.ReadXmlChildTextbox(): Textbox;
begin
if tslassigning and ifnil({self.}XmlChildTextbox) then
if tslassigning and (ifnil({self.}XmlChildTextbox) or {self.}XmlChildTextbox.Removed) then
begin
{self.}XmlChildTextbox := new Textbox(self, {self.}Prefix, "textbox");
container_.Set({self.}XmlChildTextbox);
@ -1592,7 +1592,7 @@ end;
function Shape.ReadXmlChildTextpath(): Textpath;
begin
if tslassigning and ifnil({self.}XmlChildTextpath) then
if tslassigning and (ifnil({self.}XmlChildTextpath) or {self.}XmlChildTextpath.Removed) then
begin
{self.}XmlChildTextpath := new Textpath(self, {self.}Prefix, "textpath");
container_.Set({self.}XmlChildTextpath);
@ -1602,7 +1602,7 @@ end;
function Shape.ReadXmlChildImagedata(): Imagedata;
begin
if tslassigning and ifnil({self.}XmlChildImagedata) then
if tslassigning and (ifnil({self.}XmlChildImagedata) or {self.}XmlChildImagedata.Removed) then
begin
{self.}XmlChildImagedata := new Imagedata(self, {self.}Prefix, "imagedata");
container_.Set({self.}XmlChildImagedata);
@ -1612,7 +1612,7 @@ end;
function Shape.ReadXmlChildWrap(): Wrap;
begin
if tslassigning and ifnil({self.}XmlChildWrap) then
if tslassigning and (ifnil({self.}XmlChildWrap) or {self.}XmlChildWrap.Removed) then
begin
{self.}XmlChildWrap := new Wrap(self, "w10", "wrap");
container_.Set({self.}XmlChildWrap);
@ -1627,13 +1627,13 @@ end;
function Wrap.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Wrap.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Wrap.Init();override;
@ -1653,7 +1653,7 @@ function Wrap.Copy(_obj: Wrap);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Anchorx) then
{self.}Anchorx := _obj.Anchorx;
if not ifnil(_obj.Anchory) then
@ -1698,13 +1698,13 @@ end;
function Fill.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Fill.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Fill.Init();override;
@ -1723,7 +1723,7 @@ function Fill.Copy(_obj: Fill);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Opacity) then
{self.}Opacity := _obj.Opacity;
tslassigning := tslassigning_backup;
@ -1751,13 +1751,13 @@ end;
function Imagedata.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Imagedata.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Imagedata.Init();override;
@ -1777,7 +1777,7 @@ function Imagedata.Copy(_obj: Imagedata);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Id) then
{self.}Id := _obj.Id;
if not ifnil(_obj.Title) then
@ -1822,13 +1822,13 @@ end;
function Textbox.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function Textbox.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function Textbox.Init();override;
@ -1847,7 +1847,7 @@ function Textbox.Copy(_obj: Textbox);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.XmlChildTxbxContent) then
{self.}TxbxContent.Copy(_obj.XmlChildTxbxContent);
tslassigning := tslassigning_backup;
@ -1855,7 +1855,7 @@ end;
function Textbox.ReadXmlChildTxbxContent(): TxbxContent;
begin
if tslassigning and ifnil({self.}XmlChildTxbxContent) then
if tslassigning and (ifnil({self.}XmlChildTxbxContent) or {self.}XmlChildTxbxContent.Removed) then
begin
{self.}XmlChildTxbxContent := new DocxML.TxbxContent(self, "w", "txbxContent");
container_.Set({self.}XmlChildTxbxContent);
@ -1870,13 +1870,13 @@ end;
function OLEObject.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
class(OpenXmlCompositeElement).Create(_node: XmlNode);
end;
function OLEObject.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
setsysparam(pn_calcctrlword(), getsysparam(pn_calcctrlword()) .| 0x200);
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
class(OpenXmlCompositeElement).Create(_parent, _prefix, _local_name);
end;
function OLEObject.Init();override;
@ -1900,7 +1900,7 @@ function OLEObject.Copy(_obj: OLEObject);override;
begin
tslassigning_backup := tslassigning;
tslassigning := 1;
class(OpenXmlElement).Copy(_obj);
class(OpenXmlCompositeElement).Copy(_obj);
if not ifnil(_obj.Type) then
{self.}Type := _obj.Type;
if not ifnil(_obj.ProgID) then

View File

@ -10,7 +10,6 @@ public
Prefix: string;
ElementName: string;
Value: any;
end;
function OpenXmlAttribute.Create(_prefix: string; _local_name: string);overload;

View File

@ -0,0 +1,159 @@
type OpenXmlCompositeElement = class(OpenXmlElement)
public
function InitNode(_node: XmlNode);override;
function Deserialize();override;
function Serialize();override;
function Marshal(): tableArray;override;
public
function AppendChild(_element: OpenXmlElement);
function InsertAfter(_element: OpenXmlElement; _pos_element: OpenXmlElement);
function RemoveChild(_element: OpenXmlElement);
function RemoveAttribute(_attr: OpenXmlAttribute);
// function InsertBefore(_pos_obj: tslobj; _obj: tslobj);
// function PrependChild(_obj: tslobj);
// function SetAttribute(_obj: OpenXmlAttribute);
// function RemoveAttribute();
public
function GetOrCreateNode(_obj: tslobj);
end;
function OpenXmlCompositeElement.InitNode(_node: XmlNode);override;
begin
{self.}XmlNode := _node;
if not _node then return;
tslassigning_backup := tslassigning;
tslassigning := 1;
node := _node.FirstChild();
while ifObj(node) do
begin
node_name := node.GetName();
arr := sorted_child_[node_name];
if ifarray(arr) then
begin
pf := arr[1];
obj := pf.Do();
obj.InitNode(node);
end
node := node.NextElement();
end
tslassigning := tslassigning_backup;
end;
function OpenXmlCompositeElement.Deserialize();override;
begin
if not ifObj({self.}XmlNode) then return;
attrs := {self.}XmlNode.Attributes();
for k, v in attrs do
begin
pos := pos("xmlns", k);
if pos then
begin
xmlns_[k] := k = "xmlns" ? new OpenXmlAttribute("", "xmlns", v) : new OpenXmlattribute("xmlns", k[pos+6:], v);
continue;
end
pf := attributes_pf_[k];
if ifnil(pf) then continue;
pf.Do(v);
end
child_elements := container_.GetElements();
for k, v in child_elements do
v.Deserialize();
end;
function OpenXmlCompositeElement.Serialize();override;
begin
if {self.}DeleteSelf() then return;
// xmlns
for k, v in xmlns_ do
{self.}GetNode().SetAttribute(v.ElementName, v.Value);
// Attributes
for k, v in attributes_ do
if not ifnil(v.Value) then
{self.}GetNode().SetAttribute(v.ElementName, v.Value);
else if {self.}XmlNode then
{self.}XmlNode.DeleteAttribute(v.ElementName);
// Children
child_elements := container_.GetElements();
for k, v in child_elements do
v.Serialize();
end;
function OpenXmlCompositeElement.Marshal(): tableArray;override;
begin
child_elements := container_.GetElements(false);
child_arr := array();
for k, v in child_elements do
begin
arr := array("type": "element", "name": v.ElementName, "attributes": array());
if v is Class(OpenXmlTextElement) or v is Class(OpenXmlCompositeElement) then
begin
marshal := v.Marshal();
if length(marshal["children"]) = 0 and length(marshal["attributes"]) = 0 then continue;
arr["children"] := marshal["children"];
arr["attributes"] union= marshal["attributes"];
child_arr[length(child_arr)] := arr;
end
else if v is Class(OpenXmlSimpleType) then
begin
marshal := v.Marshal();
if length(marshal) > 0 then child_arr[length(child_arr)] := arr;
end
else begin
echo "error = marshal.\n";
end
end
tmp_arr := array("type": "element", "name": {self.}ElementName, "children": child_arr, "attributes": array());
for k,v in attributes_ do
begin
if not ifnil(v.Value) then tmp_arr["attributes"][v.ElementName] := v.Value;
end
return tmp_arr;
end;
function OpenXmlCompositeElement.GetOrCreateNode(_obj: tslobj);
begin
if not ifObj({self.}XmlNode) then {self.}XmlNode := {self.}Parent.GetOrCreateNode(self);
nearest_node := nil;
child_elements := container_.GetElements(false);
for k, v in child_elements do
begin
if ifObj(v.XmlNode) then nearest_node := v.XmlNode;
if v = _obj then
begin
if ifObj(v.XmlNode) then
return v.XmlNode;
if ifnil(nearest_node) then
return {self.}XmlNode.InsertFirstChild("element", _obj.ElementName);
else
return {self.}XmlNode.InsertAfterChild(nearest_node, "element", _obj.ElementName);
end
end
raise "No child.";
end;
function OpenXmlCompositeElement.AppendChild(_element: OpenXmlElement);
begin
container_.Append(_element);
end;
function OpenXmlCompositeElement.InsertAfter(_element: OpenXmlElement; _pos_element: OpenXmlElement);
begin
container_.InsertAfter(_element, _pos_element);
end;
function OpenXmlCompositeElement.RemoveChild(_element: OpenXmlElement);
begin
_element.Removed := true;
end;
function OpenXmlCompositeElement.RemoveAttribute(_attr: OpenXmlAttribute);
begin
_attr.Value := nil;
end;

View File

@ -5,23 +5,18 @@ public
function Init();virtual;
function InitNode(_node: XmlNode);virtual;
function Copy(_obj: tslobj);virtual;
function Deserialize();virtual;
function Serialize();virtual;
function Marshal(): tableArray;virtual;
function Deserialize();
function Serialize();
function Marshal(): tableArray;
function GetOrCreateNode(_obj: tslobj);
function GetNode(): XmlNode;
function Elements(): array of tslobj;
function Attribute(_attr: string; _ns: string): OpenXmlAttribute;
function Attributes(): array of OpenXmlAttribute;
function Elements(): array of tslobj;
function Xmlns(_prefix: string): string;
public
function AppendChild(_obj: tslobj); // OpenXmlElement or OpenXmlPcdata
function InsertAfter(_obj: tslobj; _pos_obj: tslobj);
// function InsertBefore(_pos_obj: tslobj; _obj: tslobj);
// function PrependChild(_obj: tslobj);
// function RemoveChild(_obj: tslobj);
// function SetAttribute(_obj: OpenXmlAttribute);
protected
function GetNode(): XmlNode;
function DeleteSelf(): boolean;
public
LocalName: string; // 本地名称
@ -29,14 +24,14 @@ public
Prefix: string; // 前缀
XmlNode: XmlNode; // XMLNode节点
ElementName: string;
Removed: boolean; // 节点删除标记最后Serialize时候统一删除
protected
attributes_: array of OpenXmlAttribute; // 属性
attributes_pf_: tableArray;
// child_elements_: array of tslobj; // 子节点元素
xmlns_: tableArray;
sorted_child_: tableArray;
container_: TSOfficeContainer;
xmlns_: tableArray;
end;
function OpenXmlElement.Create(_node: XmlNode);overload;
@ -46,7 +41,6 @@ begin
if pos then {self.}Create(nil, node_name[:pos-1], node_name[pos+1:]);
else {self.}Create(nil, nil, node_name);
{self.}InitNode(_node);
xmlns_ := array();
end;
function OpenXmlElement.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
@ -56,122 +50,31 @@ begin
{self.}LocalName := _local_name;
{self.}XmlNode := nil;
{self.}ElementName := ifString({self.}Prefix) and {self.}Prefix <> "" ? format("%s:%s", {self.}Prefix, {self.}LocalName) : {self.}LocalName;
{self.}Removed := false;
{self.}Init();
xmlns_ := array();
end;
function OpenXmlElement.InitNode(_node: XmlNode);virtual;
function OpenXmlElement.Attribute(_attr: string; _ns: string): OpenXmlAttribute;
begin
{self.}XmlNode := _node;
if not _node then return;
tslassigning_backup := tslassigning;
tslassigning := 1;
node := _node.FirstChild();
while ifObj(node) do
begin
node_name := node.GetName();
arr := sorted_child_[node_name];
if ifarray(arr) then
begin
pf := arr[1];
obj := pf.Do();
obj.InitNode(node);
end
node := node.NextElement();
end
tslassigning := tslassigning_backup;
if ifnil(_ns) then
attr_name := ifString({self.}Prefix) and {self.}Prefix <> "" ? format("%s:%%s", {self.}Prefix, _attr) : _attr;
else
attr_name := format("%s:%s", _ns, _attr);
return attributes_[attr_name];
end;
function OpenXmlElement.GetOrCreateNode(_obj: tslobj);
function OpenXmlElement.Attributes(): array of OpenXmlAttribute;
begin
if not ifObj({self.}XmlNode) then {self.}XmlNode := {self.}Parent.GetOrCreateNode(self);
nearest_node := nil;
child_elements := container_.Get();
for k, v in child_elements do
begin
if ifObj(v.XmlNode) then nearest_node := v.XmlNode;
if v = _obj then
begin
if ifObj(v.XmlNode) then return v.XmlNode;
if ifnil(nearest_node) then return {self.}XmlNode.InsertFirstChild("element", _obj.ElementName);
else return {self.}XmlNode.InsertAfterChild(nearest_node, "element", _obj.ElementName);
end
end
raise "No child.";
end;
function OpenXmlElement.GetNode(): XmlNode;
begin
if not ifObj({self.}XmlNode) then {self.}XmlNode := {self.}Parent.GetOrCreateNode(self);
return {self.}XmlNode;
end;
function OpenXmlElement.Deserialize();
begin
if not ifObj({self.}XmlNode) then return;
attrs := {self.}XmlNode.Attributes();
for k, v in attrs do
begin
pos := pos("xmlns", k);
if pos then
begin
xmlns_[k] := k = "xmlns" ? new OpenXmlAttribute("", "xmlns", v) : new OpenXmlattribute("xmlns", k[pos+6:], v);
continue;
end
pf := attributes_pf_[k];
if ifnil(pf) then continue;
pf.Do(v);
end
child_elements := container_.Get();
for k, v in child_elements do
v.Deserialize();
end;
function OpenXmlElement.Serialize();
begin
// xmlns
for k, v in xmlns_ do
{self.}GetNode().SetAttribute(v.ElementName, v.Value);
// Attributes
attrs := array();
for k, v in attributes_ do
if not ifnil(v.Value) then {self.}GetNode().SetAttribute(v.ElementName, v.Value);
// Children
child_elements := container_.Get();
for k, v in child_elements do
v.Serialize();
attrs[length(attrs)] := v;
return attrs;
end;
function OpenXmlElement.Marshal(): tableArray;
function OpenXmlElement.Elements(): array of tslobj;
begin
child_elements := container_.Get();
child_arr := array();
for k, v in child_elements do
begin
arr := array("type": "element", "name": v.ElementName, "attributes": array());
if v is Class(OpenXmlPcdata) or v is Class(OpenXmlElement) then
begin
marshal := v.Marshal();
if length(marshal["children"]) = 0 and length(marshal["attributes"]) = 0 then continue;
arr["children"] := marshal["children"];
arr["attributes"] union= marshal["attributes"];
child_arr[length(child_arr)] := arr;
end
else if v is Class(OpenXmlEmpty) then
begin
marshal := v.Marshal();
if length(marshal) > 0 then child_arr[length(child_arr)] := arr;
end
else begin
echo "error = marshal.\n";
end
end
tmp_arr := array("type": "element", "name": {self.}ElementName, "children": child_arr, "attributes": array());
for k,v in attributes_ do
begin
if not ifnil(v.Value) then tmp_arr["attributes"][v.ElementName] := v.Value;
end
return tmp_arr;
return container_.GetElements(false);
end;
function OpenXmlElement.Xmlns(_prefix: string): string;
@ -185,17 +88,20 @@ begin
return xmlns_[k];
end;
function OpenXmlElement.Elements(): array of tslobj;
function OpenXmlElement.GetNode(): XmlNode;
begin
return container_.Get();
if not ifObj({self.}XmlNode) then {self.}XmlNode := {self.}Parent.GetOrCreateNode(self);
return {self.}XmlNode;
end;
function OpenXmlElement.InsertAfter(_obj: tslobj; _pos_obj: tslobj);
function OpenXmlElement.DeleteSelf(): boolean;
begin
container_.InsertAfter(_obj, _pos_obj);
if {self.}Removed then
begin
if {self.}XmlNode then
{self.}Parent.XmlNode.DeleteChild({self.}XmlNode);
return true;
end
return false;
end;
function OpenXmlElement.AppendChild(_obj: tslobj);
begin
container_.Append(_obj);
end;

View File

@ -1,119 +0,0 @@
type OpenXmlEmpty = class
public
function Create(_node: XmlNode);overload;
function Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
function InitNode(_node: XmlNode);
function Copy(_obj: tslobj);virtual;
function GetNode(): XmlNode;
function Marshal(): tableArray;
function BoolValue(): boolean;
function Deserialize();
function Serialize();
public
// attributes property
XmlAttrVal;
property Val read ReadXmlAttrVal write WriteXmlAttrVal;
function ReadXmlAttrVal();
function WriteXmlAttrVal(_value: any);
public
LocalName: string; // 本地名称
[weakref]Parent: tslobj; // 父类
Prefix: string; // 前缀
XmlNode: XmlNode; // XMLNode节点
ElementName: string;
Value: any;
end;
function OpenXmlEmpty.Create(_node: XmlNode);overload;
begin
node_name := _node.GetName();
pos := Pos(":", node_name);
if pos then {self.}Create(nil, node_name[:pos-1], node_name[pos+1:]);
else {self.}Create(nil, nil, node_name);
{self.}InitNode(_node);
end;
function OpenXmlEmpty.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
{self.}Parent := _parent;
{self.}Prefix := _prefix;
{self.}LocalName := _local_name;
{self.}XmlNode := nil;
{self.}ElementName := ifString({self.}Prefix) and {self.}Prefix <> "" ? format("%s:%s", {self.}Prefix, {self.}LocalName) : {self.}LocalName;
end;
function OpenXmlEmpty.InitNode(_node: XmlNode);
begin
{self.}XmlNode := ifObj(_node) ? _node : nil;
end;
function OpenXmlEmpty.Copy(_obj: tslobj);
begin
if not ifnil(_obj.Value) then {self.}Value := _obj.Value;
if not ifnil(_obj.XmlAttrVal.Value) then {self.}Val := _obj.XmlAttrVal.Value;
end;
function OpenXmlEmpty.Marshal(): tableArray;
begin
if not {self.}Value then return array();
attr := array();
if not inil({self.}XmlAttrVal.Value) then attr[{self.}XmlAttrVal.ElementName] := {self.}XmlAttrVal.Value;
arr := array("type": "element", "name": name_, "attributes": attr, "children": array());
return arr;
end;
function OpenXmlEmpty.Deserialize();
begin
if ifObj({self.}XmlNode) then
begin
attrs := {self.}XmlNode.Attributes();
if length(attrs) > 1 then raise "OpenXmlEmpty.Deserialize error.\n";
{self.}Val := nil;
for k,v in attrs do
{self.}Val := v;
{self.}Value := ifnil({self.}Val) ? true : {self.}Val = "0" ? false : true;
end
else begin
{self.}Value := nil;
{self.}XmlAttrVal := nil;
end
end;
function OpenXmlEmpty.GetNode(): XmlNode;
begin
if not ifObj({self.}XmlNode) then {self.}XmlNode := {self.}Parent.GetOrCreateNode(self);
return {self.}XmlNode;
end;
function OpenXmlEmpty.Serialize();
begin
if not ifObj({self.}XmlNode) then
begin
if not ifnil({self.}XmlAttrVal.Value) then {self.}GetNode().SetAttribute({self.}XmlAttrVal.ElementName, {self.}XmlAttrVal.Value);
end
else begin
if not ifnil({self.}XmlAttrVal.Value) then {self.}XmlNode.SetAttribute({self.}XmlAttrVal.ElementName, {self.}XmlAttrVal.Value);
else if not {self.}Value and ifObj({self.}Parent.XmlNode) then{self.}Parent.XmlNode.DeleteChild({self.}XmlNode);
end
end;
function OpenXmlEmpty.BoolValue(): boolean;
begin
return ifnil({self.}Val) ? {self.}Value ? true : false : {self.}Val;
end;
function OpenXmlEmpty.ReadXmlAttrVal();
begin
return {self.}XmlAttrVal.Value = "0" ? false : {self.}XmlAttrVal.Value = "1" ? true : {self.}XmlAttrVal.Value;
end;
function OpenXmlEmpty.WriteXmlAttrVal(_value: any);
begin
if ifnil({self.}XmlAttrVal) then
{self.}XmlAttrVal := new OpenXmlAttribute({self.}Prefix, "val", nil);
{self.}XmlAttrVal.Value := _value;
end;

View File

@ -1,87 +0,0 @@
type OpenXmlPcdata = class
public
function Create(_node: XmlNode);overload;
function Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
function Init();virtual;
function InitNode(_node: XmlNode);virtual;
function Copy(_obj: tslobj);virtual;
function GetNode(): XmlNode;
function Marshal(): tableArray;
function Deserialize();
function Serialize();
public
LocalName: string; // 本地名称
[weakref]Parent: tslobj; // 父类
Prefix: string; // 前缀
XmlNode: XmlNode; // XMLNode节点
ElementName: string;
Text: string; // 元素的文本内容
protected
attributes_: array of OpenXmlAttribute; // 属性
attributes_pf_: tableArray;
end;
function OpenXmlPcdata.Create(_node: XmlNode);overload;
begin
node_name := _node.GetName();
pos := Pos(":", node_name);
if pos then {self.}Create(nil, node_name[:pos-1], node_name[pos+1:]);
else {self.}Create(nil, nil, node_name);
{self.}InitNode(_node);
end;
function OpenXmlPcdata.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
{self.}Parent := _parent;
{self.}Prefix := _prefix;
{self.}LocalName := _local_name;
{self.}XmlNode := nil;
{self.}Text := nil;
{self.}ElementName := ifString({self.}Prefix) and {self.}Prefix <> "" ? format("%s:%s", {self.}Prefix, {self.}LocalName) : {self.}LocalName;
{self.}Init();
end;
function OpenXmlPcdata.InitNode(_node: XmlNode);virtual;
begin
{self.}XmlNode := ifObj(_node) ? _node : nil;
end;
function OpenXmlPcdata.Marshal(): tableArray;
begin
arr := array("type": "element", "name": name_, "attributes": array(), "children": array());
for k,v in attributes_ do
if not ifnil(v.Value) then arr["attributes"][v.ElementName] := v.Value;
if not ifnil({self.}Text) then arr["children"] := array(("type": "pcdata", "value": {self.}Text));
return arr;
end;
function OpenXmlPcdata.Deserialize();
begin
if not ifObj({self.}XmlNode) then return;
{self.}Text := {self.}XmlNode.GetText();
attrs := {self.}XmlNode.Attributes();
for k, v in attrs do
begin
pf := attributes_pf_[k];
if ifnil(pf) then continue;
pf.Do(v);
end
end;
function OpenXmlPcdata.GetNode(): XmlNode;
begin
if not ifObj({self.}XmlNode) then {self.}XmlNode := {self.}Parent.GetOrCreateNode(self);
return {self.}XmlNode;
end;
function OpenXmlPcdata.Serialize();
begin
if not ifnil({self.}Text) then {self.}GetNode().SetValue({self.}Text);
for k,v in attributes_ do
if not ifnil(v.Value) then {self.}GetNode().SetAttribute(v.ElementName, v.Value);
end;

View File

@ -0,0 +1,104 @@
type OpenXmlSimpleType = class(OpenXmlElement)
public
function Init();override;
function InitNode(_node: XmlNode);override;
function Copy(_obj: tslobj);override;
function Deserialize();override;
function Serialize();override;
function Marshal(): tableArray;override;
public
// attributes property
XmlAttrVal;
property Val read ReadXmlAttrVal write WriteXmlAttrVal;
function ReadXmlAttrVal();
function WriteXmlAttrVal(_value: any);
// 动态获取IsApplied
// IsApplied: boolean; // 是否已经应用和val值有关
property IsApplied read ReadIsApplied;
function ReadIsApplied();
public
Enable: boolean; // 是否启用 <b /> 没有属性需要通过val写属性
end;
function OpenXmlSimpleType.Init();override;
begin
{self.}Enable := false;
end;
function OpenXmlSimpleType.InitNode(_node: XmlNode);override;
begin
{self.}XmlNode := ifObj(_node) ? _node : nil;
end;
function OpenXmlSimpleType.Copy(_obj: tslobj);override;
begin
if not ifnil(_obj.Enable) then {self.}Enable := _obj.Enable;
if not ifnil(_obj.XmlAttrVal.Value) then {self.}Val := _obj.XmlAttrVal.Value;
end;
function OpenXmlSimpleType.Marshal(): tableArray;override;
begin
if not {self.}Enable then return array();
attr := array();
if not inil({self.}XmlAttrVal.Value) then attr[{self.}XmlAttrVal.ElementName] := {self.}XmlAttrVal.Value;
arr := array("type": "element", "name": name_, "attributes": attr, "children": array());
return arr;
end;
function OpenXmlSimpleType.Deserialize();override;
begin
if ifObj({self.}XmlNode) then
begin
attrs := {self.}XmlNode.Attributes();
if length(attrs) > 1 then
begin
echo "OpenXmlSimpleType.Deserialize error.\n";
return;
end
{self.}Val := nil;
for k,v in attrs do
{self.}Val := v;
{self.}Enable := true;
end
else begin
{self.}Enable := false;
{self.}XmlAttrVal := nil;
end
end;
function OpenXmlSimpleType.Serialize();override;
begin
if not ifObj({self.}XmlNode) then
begin
if not ifnil({self.}XmlAttrVal.Value) then {self.}GetNode().SetAttribute({self.}XmlAttrVal.ElementName, {self.}XmlAttrVal.Value);
end
else begin
if not {self.}Enable or {self.}Removed then
{self.}Parent.XmlNode.DeleteChild({self.}XmlNode);
else if not ifnil({self.}XmlAttrVal.Value) then
{self.}XmlNode.SetAttribute({self.}XmlAttrVal.ElementName, {self.}XmlAttrVal.Value);
end
end;
function OpenXmlSimpleType.ReadXmlAttrVal();
begin
return {self.}XmlAttrVal.Value;
end;
function OpenXmlSimpleType.WriteXmlAttrVal(_value: any);
begin
if ifnil({self.}XmlAttrVal) then
{self.}XmlAttrVal := new OpenXmlAttribute({self.}Prefix, "val", nil);
{self.}XmlAttrVal.Value := _value;
{self.}Enable := true;
end;
function OpenXmlSimpleType.ReadIsApplied();
begin
if {self.}Enable then
return {self.}XmlAttrVal.Value = "0" or {self.}XmlAttrVal.Value = "false" ? false : true;
return false;
end;

View File

@ -0,0 +1,59 @@
type OpenXmlTextElement = class(OpenXmlElement)
public
function InitNode(_node: XmlNode);override;
function Copy(_obj: tslobj);virtual;
function Deserialize();override;
function Serialize();override;
function Marshal(): tableArray;override;
public
Text: string; // 元素的文本内容
end;
function OpenXmlTextElement.InitNode(_node: XmlNode);override;
begin
{self.}XmlNode := ifObj(_node) ? _node : nil;
end;
function OpenXmlTextElement.Copy(_obj: tslobj);virtual;
begin
if not ifnil(_obj.Text) then {self.}Text := _obj.Text;
end;
function OpenXmlTextElement.Marshal(): tableArray;override;
begin
arr := array("type": "element", "name": name_, "attributes": array(), "children": array());
for k,v in attributes_ do
if not ifnil(v.Value) then arr["attributes"][v.ElementName] := v.Value;
if not ifnil({self.}Text) then arr["children"] := array(("type": "pcdata", "value": {self.}Text));
return arr;
end;
function OpenXmlTextElement.Deserialize();override;
begin
if not ifObj({self.}XmlNode) then return;
{self.}Text := {self.}XmlNode.GetText();
attrs := {self.}XmlNode.Attributes();
for k, v in attrs do
begin
pos := pos("xmlns", k);
if pos then
begin
xmlns_[k] := k = "xmlns" ? new OpenXmlAttribute("", "xmlns", v) : new OpenXmlattribute("xmlns", k[pos+6:], v);
continue;
end
pf := attributes_pf_[k];
if ifnil(pf) then continue;
pf.Do(v);
end
end;
function OpenXmlTextElement.Serialize();override;
begin
if {self.}DeleteSelf() then return;
if not ifnil({self.}Text) then {self.}GetNode().SetValue({self.}Text);
for k,v in attributes_ do
if not ifnil(v.Value) then {self.}GetNode().SetAttribute(v.ElementName, v.Value);
end;

View File

@ -6,8 +6,8 @@ public
function Append(data: any): boolean;
function Insert(data: any): boolean;
function InsertAfter(data: any; pos_data: any);
function Get(name: string; index: integer);overload;
function Get(): array of tslobj;overload;
function Get(name: string; index: integer);
function GetElements(include_removed: boolean): array of tslobj;
private
function GetBucketObj(str: string): LinkList;
@ -24,6 +24,7 @@ public
function Create(name: string);
function Set(data: any);
function Add(data: any);
function Delete(data: any): boolean;
function InsertAfter(data: any; pos_data: any): boolean;
function Name(): string;
function Size(): integer;
@ -58,7 +59,7 @@ function TSOfficeContainer.Set(data: any): boolean;
begin
obj := {self.}GetBucketObj(data.ElementName);
if ifnil(obj) then return false;
obj.Set(data);
obj.Add(data);
return true;
end;
@ -125,7 +126,7 @@ begin
end
end;
function TSOfficeContainer.Get(): array of tslobj;overload;
function TSOfficeContainer.GetElements(include_removed: boolean = true): array of tslobj;
begin
arr := array();
for i:=0 to current_index_ do
@ -136,6 +137,7 @@ begin
node := obj.First();
while ifObj(node) do
begin
if include_removed or not node.data.Removed then
arr[length(arr)] := node.data;
node := node.next;
end
@ -144,7 +146,7 @@ begin
return arr;
end;
function TSOfficeContainer.Get(name: string; index: integer);overload;
function TSOfficeContainer.Get(name: string; index: integer);
begin
ind := child_[name];
arr := array();
@ -239,6 +241,25 @@ begin
return false;
end;
function LinkList.Delete(data: any): boolean;
begin
node := {self.}First();
prev := nil;
while ifObj(node) do
begin
if node.data = data then
begin
if ifnil(prev) then head_.next := node.next;
else if tail_ = node then tail_ := prev;
else prev.next := node.next;
return true;
end
prev := node;
node := node.next;
end
return false;
end;
function LinkList.Name(): string;
begin
return name_;

29
迁移指南.md Normal file
View File

@ -0,0 +1,29 @@
# 迁移指南
## v2.0.0
该版本对基类做了调整
1. `OpenXmlElement` -> `OpenXmlElement`,类名不变,功能变更为基类
2. `OpenXmlPcdata` -> `OpenXmlTextElement`,类名变更,继承基类,使用方式不变
3. `OpenXmlEmpty` -> `OpenXmlSimpleType`,类名变更,继承基类,设计与使用方法需要调整
```pascal
// 弃用
rpr := new RPr();
rpr.B := true; // 启用BB是Empty元素对应xml <b/>
rpr.B.Val := 1; // <b w:val="1" />
// 读
echo rpr.B; // 判断是否启用了B
// 迁移
rpr := new RPr();
rpr.B.Enable := true; // 启用B不设置属性时候对应xml <b />
rpr.B.Val := "0"; // 会自动设置Enable为1对应xml <b w:val="0" />
// 只读
echo rpr.B.IsApplied; // 只读属性判断是否启用了B
```
4. 新增`OpenXmlCompositeElement`复杂类型的节点类,提供各种操作的方法,大部分有子节点的类均继承于该类。如`RPr`会有`B I Sz`等子节点元素,而`B I`这类的元素是`<x />`的`OpenXmlSimpleType`类型的
影响范围:列表暂无;具体可见对应类的`// simple_type property`下的属性