From 92257c380f18e2fc01a3192269e85de0fd26689e Mon Sep 17 00:00:00 2001 From: csh Date: Thu, 14 Mar 2024 14:09:55 +0800 Subject: [PATCH] v1.6.6-patch1 --- funcext/TSOffice/TOfficeObj.tsf | 16606 +++++++++++++++--------------- 1 file changed, 8304 insertions(+), 8302 deletions(-) diff --git a/funcext/TSOffice/TOfficeObj.tsf b/funcext/TSOffice/TOfficeObj.tsf index e798710..b1e5623 100644 --- a/funcext/TSOffice/TOfficeObj.tsf +++ b/funcext/TSOffice/TOfficeObj.tsf @@ -1,6 +1,6 @@ -// Version 1.6.6 -Function TOfficeObj(n); -Begin +// Version 1.6.6 +Function TOfficeObj(n); +Begin case lowercase(n) of "nodeinfo": return new NodeInfo(""); @@ -328,20 +328,20 @@ End; /////////////////////////////////////////////////////////////// /// TFont /////////////////////////////////////////////////////////////// -type TFont=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'font'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TFont=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'font'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -480,13 +480,13 @@ type TFont=class(NodeInfo) XMLUnderline := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Name','name':'name','obj':XMLName,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Size','name':'sz','obj':XMLSize,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Bold','name':'b','obj':XMLBold,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') @@ -538,20 +538,20 @@ End; /////////////////////////////////////////////////////////////// /// TComment /////////////////////////////////////////////////////////////// -type TComment=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'r'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TComment=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'r'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Font := new TFont(self, 'rPr'); //TODO... End; @@ -575,13 +575,13 @@ type TComment=class(NodeInfo) XMLText := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Font','name':Font.NodeName,'obj':Font,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TFont') ,('field':'Text','name':'t','obj':XMLText,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'Space','name':'t','obj':Space,'attrEx':'xml:space','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -599,20 +599,20 @@ End; /////////////////////////////////////////////////////////////// /// TComments /////////////////////////////////////////////////////////////// -type TComments=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'comment/text'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TComments=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'comment/text'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -621,31 +621,31 @@ type TComments=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("AuthorId", "authorId", AuthorId, ""),("Ref", "ref", Ref, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; - Function AddComment(text); - Begin - o := new TComment(self, "r"); - ExtNodes[ length(ExtNodes) ] := array("field":"", "name":"r", "obj":o, "attrEx":"", "nodeType":""); - o.Text := text; - o.Font.Bold := ""; - o.Font.Size := 9; - o.Font.rFont := "宋体"; - o.Font.Charset := 134; - return o; - End; - - Function Comment(index); - Begin - return GetNode(index); + Function AddComment(text); + Begin + o := new TComment(self, "r"); + ExtNodes[ length(ExtNodes) ] := array("field":"", "name":"r", "obj":o, "attrEx":"", "nodeType":""); + o.Text := text; + o.Font.Bold := ""; + o.Font.Size := 9; + o.Font.rFont := "宋体"; + o.Font.Charset := 134; + return o; + End; + + Function Comment(index); + Begin + return GetNode(index); End; //Attributes @@ -658,20 +658,20 @@ End; /////////////////////////////////////////////////////////////// /// TRichText /////////////////////////////////////////////////////////////// -type TRichText=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'si'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TRichText=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'si'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -680,27 +680,27 @@ type TRichText=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; - Function AddText(text); - Begin - o := new TComment(self, "r"); - ExtNodes[ length(ExtNodes) ] := array("field":"", "name":"r", "obj":o, "attrEx":"", "nodeType":""); - o.Text := text; - return o; - End; - - Function RichText(index); - Begin - return GetNode(index); + Function AddText(text); + Begin + o := new TComment(self, "r"); + ExtNodes[ length(ExtNodes) ] := array("field":"", "name":"r", "obj":o, "attrEx":"", "nodeType":""); + o.Text := text; + return o; + End; + + Function RichText(index); + Begin + return GetNode(index); End; //Attributes @@ -711,20 +711,20 @@ End; /////////////////////////////////////////////////////////////// /// TxdrFromTo /////////////////////////////////////////////////////////////// -type TxdrFromTo=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xdr:from'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TxdrFromTo=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xdr:from'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -733,13 +733,13 @@ type TxdrFromTo=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Col','name':'xdr:col','obj':Col,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'ColOff','name':'xdr:colOff','obj':ColOff,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'Row','name':'xdr:row','obj':Row,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') @@ -759,20 +759,20 @@ End; /////////////////////////////////////////////////////////////// /// TOff /////////////////////////////////////////////////////////////// -type TOff=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:off'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TOff=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:off'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -781,13 +781,13 @@ type TOff=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("X", "x", X, ""),("Y", "y", Y, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -801,20 +801,20 @@ End; /////////////////////////////////////////////////////////////// /// TExt /////////////////////////////////////////////////////////////// -type TExt=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:ext'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TExt=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:ext'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -823,13 +823,13 @@ type TExt=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Cx", "cx", Cx, ""),("Cy", "cy", Cy, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -843,20 +843,20 @@ End; /////////////////////////////////////////////////////////////// /// TXfrm /////////////////////////////////////////////////////////////// -type TXfrm=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:xfrm'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TXfrm=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:xfrm'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Off := new TOff(self, 'a:off'); Ext := new TExt(self, 'a:ext'); //TODO... @@ -869,13 +869,13 @@ type TXfrm=class(NodeInfo) Ext.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Off','name':Off.NodeName,'obj':Off,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TOff') ,('field':'Ext','name':Ext.NodeName,'obj':Ext,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TExt') ) union ExtNodes; @@ -891,20 +891,20 @@ End; /////////////////////////////////////////////////////////////// /// TClientData /////////////////////////////////////////////////////////////// -type TClientData=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'x:ClientData'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TClientData=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'x:ClientData'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin ObjectType := "Note"; //TODO... End; @@ -914,13 +914,13 @@ type TClientData=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("ObjectType", "ObjectType", ObjectType, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'MoveWithCells','name':'x:MoveWithCells','obj':MoveWithCells,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ,('field':'SizeWithCells','name':'x:SizeWithCells','obj':SizeWithCells,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ,('field':'Anchor','name':'x:Anchor','obj':Anchor,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') @@ -945,20 +945,20 @@ End; /////////////////////////////////////////////////////////////// /// TGraphicFramePr /////////////////////////////////////////////////////////////// -type TGraphicFramePr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xdr:cNvGraphicFramePr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TGraphicFramePr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xdr:cNvGraphicFramePr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -967,13 +967,13 @@ type TGraphicFramePr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Id','name':'xdr:cNvPr','obj':Id,'attrEx':'id','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Name','name':'xdr:cNvPr','obj':Name,'attrEx':'name','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'cNvGraphicFramePr','name':'xdr:cNvGraphicFramePr','obj':cNvGraphicFramePr,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') @@ -991,20 +991,20 @@ End; /////////////////////////////////////////////////////////////// /// TGraphicFrame /////////////////////////////////////////////////////////////// -type TGraphicFrame=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xdr:graphicFrame'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TGraphicFrame=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xdr:graphicFrame'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin GraphicFramePr := new TGraphicFramePr(self, 'xdr:nvGraphicFramePr'); Xfrm := new TXfrm(self, 'xdr:xfrm'); Graphic := new TGraphic(self, 'a:graphic'); @@ -1019,13 +1019,13 @@ type TGraphicFrame=class(NodeInfo) Graphic.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("macro", "macro", macro, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'GraphicFramePr','name':GraphicFramePr.NodeName,'obj':GraphicFramePr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TGraphicFramePr') ,('field':'Xfrm','name':Xfrm.NodeName,'obj':Xfrm,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TXfrm') ,('field':'Graphic','name':Graphic.NodeName,'obj':Graphic,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TGraphic') @@ -1044,20 +1044,20 @@ End; /////////////////////////////////////////////////////////////// /// TtwoCellAnchor /////////////////////////////////////////////////////////////// -type TtwoCellAnchor=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xdr:twoCellAnchor'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TtwoCellAnchor=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xdr:twoCellAnchor'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin XFrom := new TxdrFromTo(self, 'xdr:from'); XTo := new TxdrFromTo(self, 'xdr:to'); GraphicFrame := new TGraphicFrame(self, 'xdr:graphicFrame'); @@ -1076,13 +1076,13 @@ type TtwoCellAnchor=class(NodeInfo) ClientData.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("EditAs", "editAs", EditAs, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'XFrom','name':XFrom.NodeName,'obj':XFrom,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TxdrFromTo') ,('field':'XTo','name':XTo.NodeName,'obj':XTo,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TxdrFromTo') ,('field':'GraphicFrame','name':GraphicFrame.NodeName,'obj':GraphicFrame,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TGraphicFrame') @@ -1105,20 +1105,20 @@ End; /////////////////////////////////////////////////////////////// /// TcNvPicPr /////////////////////////////////////////////////////////////// -type TcNvPicPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xdr:cNvPicPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcNvPicPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xdr:cNvPicPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -1127,13 +1127,13 @@ type TcNvPicPr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'PicLocks','name':'a:picLocks','obj':PicLocks,'attrEx':'noChangeAspect','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -1147,20 +1147,20 @@ End; /////////////////////////////////////////////////////////////// /// TPictureFormat /////////////////////////////////////////////////////////////// -type TPictureFormat=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, ''); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPictureFormat=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, ''); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin BegColOff := 0; BegRowOff := 0; EndColOff := 0; @@ -1173,13 +1173,13 @@ type TPictureFormat=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'BegColOff','name':'BegColOff','obj':BegColOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'BegRowOff','name':'BegRowOff','obj':BegRowOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'EndColOff','name':'EndColOff','obj':EndColOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -1199,20 +1199,20 @@ End; /////////////////////////////////////////////////////////////// /// TShapeFormat /////////////////////////////////////////////////////////////// -type TShapeFormat=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, ''); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TShapeFormat=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, ''); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -1221,13 +1221,13 @@ type TShapeFormat=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'BegColOff','name':'BegColOff','obj':BegColOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'BegRowOff','name':'BegRowOff','obj':BegRowOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'EndColOff','name':'EndColOff','obj':EndColOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -1235,15 +1235,15 @@ type TShapeFormat=class(NodeInfo) ) union ExtNodes; End; - Function AddText(text); - Begin - o := new TaP(self, "a:p"); - o.R.Rpr.Lang := "en-US"; - o.R.Rpr.AltLang := "zh-CN"; - o.R.Rpr.SZ := 2400; - o.Ppr.Algn := "l"; - ExtNodes[ length(ExtNodes) ] := array("field":"", "name":"a:p", "obj":o, "attrEx":"", "nodeType":""); - return o; + Function AddText(text); + Begin + o := new TaP(self, "a:p"); + o.R.Rpr.Lang := "en-US"; + o.R.Rpr.AltLang := "zh-CN"; + o.R.Rpr.SZ := 2400; + o.Ppr.Algn := "l"; + ExtNodes[ length(ExtNodes) ] := array("field":"", "name":"a:p", "obj":o, "attrEx":"", "nodeType":""); + return o; End; //Attributes @@ -1258,20 +1258,20 @@ End; /////////////////////////////////////////////////////////////// /// TChartImpl /////////////////////////////////////////////////////////////// -type TChartImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 't:chart'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TChartImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 't:chart'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Series := array(); XAxis := new TChartAxis(self, 'XAxis'); YAxis := new TChartAxis(self, 'YAxis'); @@ -1289,13 +1289,13 @@ type TChartImpl=class(NodeInfo) Plotarea.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Width','name':'Width','obj':Width,'attrEx':'','nodeType':'','attrName':'', 'desc':'word图表宽度(cm)', 'class':'') ,('field':'Height','name':'Height','obj':Height,'attrEx':'','nodeType':'','attrName':'', 'desc':'word图表高度(cm)', 'class':'') ,('field':'BegColOff','name':'BegColOff','obj':BegColOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'disable', 'class':'') @@ -1381,20 +1381,20 @@ End; /////////////////////////////////////////////////////////////// /// TLegend /////////////////////////////////////////////////////////////// -type TLegend=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:legend'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TLegend=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:legend'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -1403,28 +1403,28 @@ type TLegend=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'legendPos','name':'c:legendPos','obj':legendPos,'attrEx':'val','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Layout','name':'c:layout','obj':Layout,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ,('field':'overlay','name':'c:overlay','obj':overlay,'attrEx':'val','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; - Property Position write setPosition; - Function setPosition(t); - Begin - m := array("bottom": "b", - "left": "l", - "right": "r", - "top": "t", - "top_right": "tr"); - legendPos := m[t]; + Property Position write setPosition; + Function setPosition(t); + Begin + m := array("bottom": "b", + "left": "l", + "right": "r", + "top": "t", + "top_right": "tr"); + legendPos := m[t]; End; //Attributes @@ -1438,20 +1438,20 @@ End; /////////////////////////////////////////////////////////////// /// TChartAxis /////////////////////////////////////////////////////////////// -type TChartAxis=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'ChartAxis'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TChartAxis=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'ChartAxis'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin NumFont := new TNumFont(self, 'NumFont'); NameLayout := new TNameLayout(self, 'NameLayout'); //TODO... @@ -1464,13 +1464,13 @@ type TChartAxis=class(NodeInfo) NameLayout.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'None','name':'None','obj':None,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Crossing','name':'Crossing','obj':Crossing,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'MajorGridlines','name':'MajorGridlines','obj':MajorGridlines,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -1522,20 +1522,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumFont /////////////////////////////////////////////////////////////// -type TNumFont=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'NumFont'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumFont=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'NumFont'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -1544,13 +1544,13 @@ type TNumFont=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Color','name':'Color','obj':Color,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Bold','name':'Bold','obj':Bold,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Italic','name':'Italic','obj':Italic,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -1570,20 +1570,20 @@ End; /////////////////////////////////////////////////////////////// /// TNameLayout /////////////////////////////////////////////////////////////// -type TNameLayout=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'NameLayout'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNameLayout=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'NameLayout'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -1592,13 +1592,13 @@ type TNameLayout=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'X','name':'X','obj':X,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Y','name':'Y','obj':Y,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Width','name':'Width','obj':Width,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -1618,20 +1618,20 @@ End; /////////////////////////////////////////////////////////////// /// Tpt /////////////////////////////////////////////////////////////// -type Tpt=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:pt'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type Tpt=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:pt'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -1640,13 +1640,13 @@ type Tpt=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("IDx", "idx", IDx, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'V','name':'c:v','obj':V,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -1661,20 +1661,20 @@ End; /////////////////////////////////////////////////////////////// /// TStrCache /////////////////////////////////////////////////////////////// -type TStrCache=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:strRef'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TStrCache=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:strRef'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Pt := new Tpt(self, 'c:pt'); //TODO... End; @@ -1685,13 +1685,13 @@ type TStrCache=class(NodeInfo) Pt.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'PtCount','name':'c:ptCount','obj':PtCount,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Pt','name':Pt.NodeName,'obj':Pt,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'Tpt') ) union ExtNodes; @@ -1707,20 +1707,20 @@ End; /////////////////////////////////////////////////////////////// /// TStrRef /////////////////////////////////////////////////////////////// -type TStrRef=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:strRef'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TStrRef=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:strRef'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin StrCache := new TStrCache(self, 'c:strCache'); //TODO... End; @@ -1731,13 +1731,13 @@ type TStrRef=class(NodeInfo) StrCache.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'F','name':'c:f','obj':F,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'StrCache','name':StrCache.NodeName,'obj':StrCache,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStrCache') ) union ExtNodes; @@ -1753,20 +1753,20 @@ End; /////////////////////////////////////////////////////////////// /// TcCat /////////////////////////////////////////////////////////////// -type TcCat=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:cat'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcCat=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:cat'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin StrRef := new TStrRef(self, 'c:strRef'); //TODO... End; @@ -1777,13 +1777,13 @@ type TcCat=class(NodeInfo) StrRef.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'StrRef','name':StrRef.NodeName,'obj':StrRef,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStrRef') ) union ExtNodes; End; @@ -1797,20 +1797,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumCache /////////////////////////////////////////////////////////////// -type TNumCache=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:numCache'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumCache=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:numCache'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Pt := new Tpt(self, 'c:pt'); //TODO... End; @@ -1821,13 +1821,13 @@ type TNumCache=class(NodeInfo) Pt.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'FormatCode','name':'c:formatCode','obj':FormatCode,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'PtCount','name':'c:ptCount','obj':PtCount,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Pt','name':Pt.NodeName,'obj':Pt,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'Tpt') @@ -1845,20 +1845,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumRef /////////////////////////////////////////////////////////////// -type TNumRef=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:numRef'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumRef=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:numRef'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin NumCache := new TNumCache(self, 'c:numCache'); //TODO... End; @@ -1869,13 +1869,13 @@ type TNumRef=class(NodeInfo) NumCache.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'F','name':'c:f','obj':F,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'NumCache','name':NumCache.NodeName,'obj':NumCache,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TNumCache') ) union ExtNodes; @@ -1891,20 +1891,20 @@ End; /////////////////////////////////////////////////////////////// /// TcVal /////////////////////////////////////////////////////////////// -type TcVal=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:val'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcVal=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:val'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin NumRef := new TNumRef(self, 'c:numRef'); //TODO... End; @@ -1915,13 +1915,13 @@ type TcVal=class(NodeInfo) NumRef.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'NumRef','name':NumRef.NodeName,'obj':NumRef,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TNumRef') ) union ExtNodes; End; @@ -1935,20 +1935,20 @@ End; /////////////////////////////////////////////////////////////// /// TTx /////////////////////////////////////////////////////////////// -type TTx=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:tx'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTx=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:tx'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin StrRef := new TStrRef(self, 'c:strRef'); //TODO... End; @@ -1959,13 +1959,13 @@ type TTx=class(NodeInfo) StrRef.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'StrRef','name':StrRef.NodeName,'obj':StrRef,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStrRef') ) union ExtNodes; End; @@ -1979,20 +1979,20 @@ End; /////////////////////////////////////////////////////////////// /// TSolidFill /////////////////////////////////////////////////////////////// -type TSolidFill=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:solidFill'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSolidFill=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:solidFill'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SchemeClr := new TSchemeClr(self, 'a:schemeClr'); //TODO... End; @@ -2003,13 +2003,13 @@ type TSolidFill=class(NodeInfo) SchemeClr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'SchemeClr','name':SchemeClr.NodeName,'obj':SchemeClr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSchemeClr') ,('field':'SrgbClr','name':'a:srgbClr','obj':SrgbClr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; @@ -2025,20 +2025,20 @@ End; /////////////////////////////////////////////////////////////// /// TSchemeClr /////////////////////////////////////////////////////////////// -type TSchemeClr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:schemeClr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSchemeClr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:schemeClr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2047,13 +2047,13 @@ type TSchemeClr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Val", "val", Val, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'LumMod','name':'a:lumMod','obj':LumMod,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'LumOff','name':'a:lumOff','obj':LumOff,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; @@ -2070,20 +2070,20 @@ End; /////////////////////////////////////////////////////////////// /// TLn /////////////////////////////////////////////////////////////// -type TLn=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 't:Ln'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TLn=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 't:Ln'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SolidFill := new TSolidFill(self, 'a:solidFill'); //TODO... End; @@ -2094,13 +2094,13 @@ type TLn=class(NodeInfo) SolidFill.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Algn", "algn", Algn, ""),("Cap", "cap", Cap, ""),("Cmpd", "cmpd", Cmpd, ""),("W", "w", W, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'NoFill','name':'a:noFill','obj':NoFill,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ,('field':'prstDash','name':'a:prstDash','obj':prstDash,'attrEx':'val','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Round','name':'a:round','obj':Round,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') @@ -2124,20 +2124,20 @@ End; /////////////////////////////////////////////////////////////// /// TContourClr /////////////////////////////////////////////////////////////// -type TContourClr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:contourClr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TContourClr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:contourClr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SchemeClr := new TSchemeClr(self, 'a:schemeClr'); //TODO... End; @@ -2148,13 +2148,13 @@ type TContourClr=class(NodeInfo) SchemeClr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'SchemeClr','name':SchemeClr.NodeName,'obj':SchemeClr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSchemeClr') ) union ExtNodes; End; @@ -2168,20 +2168,20 @@ End; /////////////////////////////////////////////////////////////// /// TSp3D /////////////////////////////////////////////////////////////// -type TSp3D=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:sp3d'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSp3D=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:sp3d'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin ContourClr := new TContourClr(self, 'a:contourClr'); //TODO... End; @@ -2192,13 +2192,13 @@ type TSp3D=class(NodeInfo) ContourClr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("ContourW", "contourW", ContourW, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'ContourClr','name':ContourClr.NodeName,'obj':ContourClr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TContourClr') ) union ExtNodes; End; @@ -2213,20 +2213,20 @@ End; /////////////////////////////////////////////////////////////// /// TspPr /////////////////////////////////////////////////////////////// -type TspPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:spPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TspPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:spPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SolidFill := new TSolidFill(self, 'a:solidFill'); Ln := new TLn(self, 'a:ln'); Sp3D := new TSp3D(self, 'a:sp3d'); @@ -2245,13 +2245,13 @@ type TspPr=class(NodeInfo) PrstGeom.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'NoFill','name':'a:noFill','obj':NoFill,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ,('field':'SolidFill','name':SolidFill.NodeName,'obj':SolidFill,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSolidFill') ,('field':'Ln','name':Ln.NodeName,'obj':Ln,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TLn') @@ -2277,20 +2277,20 @@ End; /////////////////////////////////////////////////////////////// /// TDpt /////////////////////////////////////////////////////////////// -type TDpt=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:dPt'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TDpt=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:dPt'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SpPr := new TspPr(self, 'c:spPr'); //TODO... End; @@ -2301,13 +2301,13 @@ type TDpt=class(NodeInfo) SpPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'IDx','name':'c:idx','obj':IDx,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Bubble3D','name':'c:bubble3D','obj':Bubble3D,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'SpPr','name':SpPr.NodeName,'obj':SpPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TspPr') @@ -2325,20 +2325,20 @@ End; /////////////////////////////////////////////////////////////// /// TMarker /////////////////////////////////////////////////////////////// -type TMarker=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:marker'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TMarker=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:marker'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SpPr := new TspPr(self, 'c:spPr'); //TODO... End; @@ -2349,13 +2349,13 @@ type TMarker=class(NodeInfo) SpPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Symbol','name':'c:symbol','obj':Symbol,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Size','name':'c:size','obj':Size,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'SpPr','name':SpPr.NodeName,'obj':SpPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TspPr') @@ -2373,20 +2373,20 @@ End; /////////////////////////////////////////////////////////////// /// TSer /////////////////////////////////////////////////////////////// -type TSer=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:ser'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSer=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:ser'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Tx := new TTx(self, 'c:tx'); SpPr := new TspPr(self, 'c:spPr'); DPt := new TDpt(self, 'c:dPt'); @@ -2416,13 +2416,13 @@ type TSer=class(NodeInfo) BubbleSize.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'IDx','name':'c:idx','obj':IDx,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Ord','name':'c:order','obj':Ord,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Tx','name':Tx.NodeName,'obj':Tx,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TTx') @@ -2466,20 +2466,20 @@ End; /////////////////////////////////////////////////////////////// /// TdLbls /////////////////////////////////////////////////////////////// -type TdLbls=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:dLbls'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TdLbls=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:dLbls'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2488,13 +2488,13 @@ type TdLbls=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Del','name':'c:delete','obj':Del,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ShowLegendKey','name':'c:showLegendKey','obj':ShowLegendKey,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ShowVal','name':'c:showVal','obj':ShowVal,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -2522,20 +2522,20 @@ End; /////////////////////////////////////////////////////////////// /// TcCharts /////////////////////////////////////////////////////////////// -type TcCharts=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:chart'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcCharts=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:chart'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Ser := array(); DLbls := new TdLbls(self, 'c:dLbls'); //TODO... @@ -2547,13 +2547,13 @@ type TcCharts=class(NodeInfo) DLbls.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'BarDir','name':'c:barDir','obj':BarDir,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'BubbleScale','name':'c:bubbleScale','obj':BubbleScale,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Grouping','name':'c:grouping','obj':Grouping,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -2601,20 +2601,20 @@ End; /////////////////////////////////////////////////////////////// /// TcScaling /////////////////////////////////////////////////////////////// -type TcScaling=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:scaling'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcScaling=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:scaling'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2623,13 +2623,13 @@ type TcScaling=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'LogBase','name':'c:logBase','obj':LogBase,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Orientation','name':'c:orientation','obj':Orientation,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Max','name':'c:max','obj':Max,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -2649,20 +2649,20 @@ End; /////////////////////////////////////////////////////////////// /// TcChartLines /////////////////////////////////////////////////////////////// -type TcChartLines=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:cChartLines'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcChartLines=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:cChartLines'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SpPr := new TspPr(self, 'c:spPr'); //TODO... End; @@ -2673,13 +2673,13 @@ type TcChartLines=class(NodeInfo) SpPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'SpPr','name':SpPr.NodeName,'obj':SpPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TspPr') ) union ExtNodes; End; @@ -2693,20 +2693,20 @@ End; /////////////////////////////////////////////////////////////// /// TcNumFmt /////////////////////////////////////////////////////////////// -type TcNumFmt=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:numFmt'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcNumFmt=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:numFmt'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2715,13 +2715,13 @@ type TcNumFmt=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("FormatCode", "formatCode", FormatCode, ""),("SourceLinked", "sourceLinked", SourceLinked, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -2735,20 +2735,20 @@ End; /////////////////////////////////////////////////////////////// /// TaR /////////////////////////////////////////////////////////////// -type TaR=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:r'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaR=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:r'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Rpr := new TaRpr(self, 'a:rPr'); //TODO... End; @@ -2759,13 +2759,13 @@ type TaR=class(NodeInfo) Rpr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Rpr','name':Rpr.NodeName,'obj':Rpr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaRpr') ,('field':'T','name':'a:t','obj':T,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; @@ -2781,20 +2781,20 @@ End; /////////////////////////////////////////////////////////////// /// TaEndParaRPr /////////////////////////////////////////////////////////////// -type TaEndParaRPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:endParaRPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaEndParaRPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:endParaRPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2803,13 +2803,13 @@ type TaEndParaRPr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Lang", "lang", Lang, ""),("AltLang", "altLang", AltLang, ""),("Sz", "sz", Sz, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -2824,20 +2824,20 @@ End; /////////////////////////////////////////////////////////////// /// TaP /////////////////////////////////////////////////////////////// -type TaP=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:p'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaP=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:p'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Ppr := new TaPPr(self, 'a:pPr'); R := new TaR(self, 'a:r'); EndParaRPr := new TaEndParaRPr(self, 'a:endParaRPr'); @@ -2852,13 +2852,13 @@ type TaP=class(NodeInfo) EndParaRPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Ppr','name':Ppr.NodeName,'obj':Ppr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaPPr') ,('field':'R','name':R.NodeName,'obj':R,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaR') ,('field':'EndParaRPr','name':EndParaRPr.NodeName,'obj':EndParaRPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaEndParaRPr') @@ -2876,20 +2876,20 @@ End; /////////////////////////////////////////////////////////////// /// TaPPr /////////////////////////////////////////////////////////////// -type TaPPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:pPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaPPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:pPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin DefRPr := new TaRPr(self, 'a:defRPr'); //TODO... End; @@ -2900,13 +2900,13 @@ type TaPPr=class(NodeInfo) DefRPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Algn", "algn", Algn, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'DefRPr','name':DefRPr.NodeName,'obj':DefRPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaRPr') ) union ExtNodes; End; @@ -2921,20 +2921,20 @@ End; /////////////////////////////////////////////////////////////// /// TaLatin /////////////////////////////////////////////////////////////// -type TaLatin=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:latin'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaLatin=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:latin'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2943,13 +2943,13 @@ type TaLatin=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Typeface", "typeface", Typeface, ""),("Panose", "panose", Panose, ""),("PitchFamily", "pitchFamily", PitchFamily, ""),("Charset", "charset", Charset, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -2965,20 +2965,20 @@ End; /////////////////////////////////////////////////////////////// /// TaEa /////////////////////////////////////////////////////////////// -type TaEa=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:ea'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaEa=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:ea'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -2987,13 +2987,13 @@ type TaEa=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Typeface", "typeface", Typeface, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -3006,20 +3006,20 @@ End; /////////////////////////////////////////////////////////////// /// TaCs /////////////////////////////////////////////////////////////// -type TaCs=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:cs'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaCs=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:cs'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -3028,13 +3028,13 @@ type TaCs=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Typeface", "typeface", Typeface, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -3047,20 +3047,20 @@ End; /////////////////////////////////////////////////////////////// /// TaRPr /////////////////////////////////////////////////////////////// -type TaRPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:defRPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaRPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:defRPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SolidFill := new TSolidFill(self, 'a:solidFill'); Latin := new TaLatin(self, 'a:latin'); Ea := new TaEa(self, 'a:ea'); @@ -3077,13 +3077,13 @@ type TaRPr=class(NodeInfo) Cs.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("AltLang", "altLang", AltLang, ""),("Bold", "b", Bold, ""),("Baseline", "baseline", Baseline, ""),("Bmk", "bmk", Bmk, ""),("Cap", "cap", Cap, ""),("Dirty", "dirty", Dirty, ""),("Err", "err", Err, ""),("Italic", "i", Italic, ""),("Kern", "kern", Kern, ""),("Kumimoji", "kumimoji", Kumimoji, ""),("Lang", "lang", Lang, ""),("NoProof", "noProof", NoProof, ""),("NormalizeH", "normalizeH", NormalizeH, ""),("SmtID", "smtId", SmtID, ""),("Spc", "spc", Spc, ""),("Strike", "strike", Strike, ""),("Sz", "sz", Sz, ""),("SmtClean", "smtClean", SmtClean, ""),("U", "u", U, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'SolidFill','name':SolidFill.NodeName,'obj':SolidFill,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSolidFill') ,('field':'Latin','name':Latin.NodeName,'obj':Latin,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaLatin') ,('field':'Ea','name':Ea.NodeName,'obj':Ea,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaEa') @@ -3122,20 +3122,20 @@ End; /////////////////////////////////////////////////////////////// /// TaBodyPr /////////////////////////////////////////////////////////////// -type TaBodyPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:bodyPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TaBodyPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:bodyPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -3144,13 +3144,13 @@ type TaBodyPr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Vert", "vert", Vert, ""),("VertOverflow", "vertOverflow", VertOverflow, ""),("HorzOverflow", "horzOverflow", HorzOverflow, ""),("RtlCol", "rtlCol", RtlCol, ""),("Anchor", "anchor", Anchor, ""),("AnchorCtr", "anchorCtr", AnchorCtr, ""),("Rot", "rot", Rot, ""),("BIns", "bIns", BIns, ""),("CompatLnSpc", "compatLnSpc", CompatLnSpc, ""),("ForceAA", "forceAA", ForceAA, ""),("FromWordArt", "fromWordArt", FromWordArt, ""),("LIns", "lIns", LIns, ""),("NumCol", "numCol", NumCol, ""),("RIns", "rIns", RIns, ""),("SpcCol", "spcCol", SpcCol, ""),("SpcFirstLastPara", "spcFirstLastPara", SpcFirstLastPara, ""),("TIns", "tIns", TIns, ""),("Upright", "upright", Upright, ""),("Wrap", "wrap", Wrap, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -3181,20 +3181,20 @@ End; /////////////////////////////////////////////////////////////// /// TTxPr /////////////////////////////////////////////////////////////// -type TTxPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'txPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTxPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'txPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin BodyPr := new TaBodyPr(self, 'a:bodyPr'); P := new TaP(self, 'a:p'); //TODO... @@ -3207,13 +3207,13 @@ type TTxPr=class(NodeInfo) P.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'BodyPr','name':BodyPr.NodeName,'obj':BodyPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaBodyPr') ,('field':'LstStyle','name':'a:lstStyle','obj':LstStyle,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'P','name':P.NodeName,'obj':P,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TaP') @@ -3231,20 +3231,20 @@ End; /////////////////////////////////////////////////////////////// /// TcAxs /////////////////////////////////////////////////////////////// -type TcAxs=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:catAx'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcAxs=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:catAx'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Scaling := new TcScaling(self, 'c:scaling'); MajorGridlines := new TcChartLines(self, 'c:majorGridlines'); MinorGridlines := new TcChartLines(self, 'c:minorGridlines'); @@ -3265,13 +3265,13 @@ type TcAxs=class(NodeInfo) TxPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'AxID','name':'c:axId','obj':AxID,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Scaling','name':Scaling.NodeName,'obj':Scaling,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TcScaling') ,('field':'Del','name':'c:delete','obj':Del,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -3329,20 +3329,20 @@ End; /////////////////////////////////////////////////////////////// /// TplotArea /////////////////////////////////////////////////////////////// -type TplotArea=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:plotArea'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TplotArea=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:plotArea'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Chart := new TcCharts(self, 'c:chartname'); CatAx := new TcAxs(self, 'c:catAx'); ValAx := new TcAxs(self, 'c:valAx'); @@ -3361,13 +3361,13 @@ type TplotArea=class(NodeInfo) SpPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Layout','name':'c:layout','obj':Layout,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ,('field':'Chart','name':Chart.NodeName,'obj':Chart,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TcCharts') ,('field':'CatAx','name':CatAx.NodeName,'obj':CatAx,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TcAxs') @@ -3391,20 +3391,20 @@ End; /////////////////////////////////////////////////////////////// /// TView3D /////////////////////////////////////////////////////////////// -type TView3D=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'c:view3D'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TView3D=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'c:view3D'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -3413,13 +3413,13 @@ type TView3D=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'RotX','name':'c:rotX','obj':RotX,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'RotY','name':'c:rotY','obj':RotY,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'RAngAx','name':'c:rAngAx','obj':RAngAx,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -3441,20 +3441,20 @@ End; /////////////////////////////////////////////////////////////// /// TBorder /////////////////////////////////////////////////////////////// -type TBorder=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'border'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TBorder=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'border'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -3515,13 +3515,13 @@ type TBorder=class(NodeInfo) XMLLineStyle := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("LineStyle", "style", XMLLineStyle, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Color','name':'color','obj':XMLColor,'attrEx':'rgb','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ThemeColor','name':'color','obj':XMLThemeColor,'attrEx':'theme','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ThemeColorTint','name':'color','obj':XMLThemeColorTint,'attrEx':'tint','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -3544,20 +3544,20 @@ End; /////////////////////////////////////////////////////////////// /// TBorders /////////////////////////////////////////////////////////////// -type TBorders=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'border'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TBorders=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'border'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Left := new TBorder(self, 'left'); Right := new TBorder(self, 'right'); Top := new TBorder(self, 'top'); @@ -3602,13 +3602,13 @@ type TBorders=class(NodeInfo) XMLDiagonalUp := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("DiagonalDown", "diagonalDown", XMLDiagonalDown, ""),("DiagonalUp", "diagonalUp", XMLDiagonalUp, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Left','name':Left.NodeName,'obj':Left,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TBorder') ,('field':'Right','name':Right.NodeName,'obj':Right,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TBorder') ,('field':'Top','name':Top.NodeName,'obj':Top,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TBorder') @@ -3632,20 +3632,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumFmts /////////////////////////////////////////////////////////////// -type TNumFmts=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'numFmts'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumFmts=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'numFmts'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -3667,13 +3667,13 @@ type TNumFmts=class(NodeInfo) XMLFormatCode := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("NumFmtId", "numFmtId", NumFmtId, ""),("FormatCode", "formatCode", XMLFormatCode, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -3687,20 +3687,20 @@ End; /////////////////////////////////////////////////////////////// /// TGradient /////////////////////////////////////////////////////////////// -type TGradient=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'gradientFill'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TGradient=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'gradientFill'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Stop1 := new TStop(self, 'stop'); Stop2 := new TStop(self, 'stop'); Stop3 := new TStop(self, 'stop'); @@ -3793,13 +3793,13 @@ type TGradient=class(NodeInfo) XMLBottom := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Degree", "degree", XMLDegree, ""),("Type", "type", XMLType, ""),("Left", "left", XMLLeft, ""),("Right", "right", XMLRight, ""),("Top", "top", XMLTop, ""),("Bottom", "bottom", XMLBottom, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Stop1','name':Stop1.NodeName,'obj':Stop1,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStop') ,('field':'Stop2','name':Stop2.NodeName,'obj':Stop2,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStop') ,('field':'Stop3','name':Stop3.NodeName,'obj':Stop3,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStop') @@ -3823,20 +3823,20 @@ End; /////////////////////////////////////////////////////////////// /// TFills /////////////////////////////////////////////////////////////// -type TFills=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'fill'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TFills=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'fill'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Pattern := new TPattern(self, 'patternFill'); Gradient := new TGradient(self, 'gradientFill'); //TODO... @@ -3849,13 +3849,13 @@ type TFills=class(NodeInfo) Gradient.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Pattern','name':Pattern.NodeName,'obj':Pattern,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TPattern') ,('field':'Gradient','name':Gradient.NodeName,'obj':Gradient,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TGradient') ) union ExtNodes; @@ -3871,20 +3871,20 @@ End; /////////////////////////////////////////////////////////////// /// TPattern /////////////////////////////////////////////////////////////// -type TPattern=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'patternFill'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPattern=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'patternFill'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -3984,13 +3984,13 @@ type TPattern=class(NodeInfo) XMLBackgroundThemeColorTint := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("PatternType", "patternType", XMLPatternType, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'ForegroundColor','name':'fgColor','obj':XMLForegroundColor,'attrEx':'rgb','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'BackgroundColor','name':'bgColor','obj':XMLBackgroundColor,'attrEx':'rgb','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ForegroundThemeColor','name':'fgColor','obj':XMLForegroundThemeColor,'attrEx':'theme','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -4015,20 +4015,20 @@ End; /////////////////////////////////////////////////////////////// /// TStop /////////////////////////////////////////////////////////////// -type TStop=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'stop'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TStop=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'stop'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4102,13 +4102,13 @@ type TStop=class(NodeInfo) XMLThemeColorTint := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Position", "position", XMLPosition, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Color','name':'color','obj':XMLColor,'attrEx':'rgb','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ColorIndex','name':'color','obj':XMLColorIndex,'attrEx':'index','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'ThemeColor','name':'color','obj':XMLThemeColor,'attrEx':'theme','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -4129,20 +4129,20 @@ End; /////////////////////////////////////////////////////////////// /// TAlignment /////////////////////////////////////////////////////////////// -type TAlignment=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'alignment'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TAlignment=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'alignment'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4216,13 +4216,13 @@ type TAlignment=class(NodeInfo) XMLTextRotation := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Horizontal", "horizontal", XMLHorizontal, ""),("Vertical", "vertical", XMLVertical, ""),("WrapText", "wrapText", XMLWrapText, ""),("ReadingOrder", "readingOrder", XMLReadingOrder, ""),("TextRotation", "textRotation", XMLTextRotation, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -4239,20 +4239,20 @@ End; /////////////////////////////////////////////////////////////// /// TProtection /////////////////////////////////////////////////////////////// -type TProtection=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'protection'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TProtection=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'protection'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4287,13 +4287,13 @@ type TProtection=class(NodeInfo) XMLHide := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Lock", "locked", XMLLock, ""),("Hide", "hidden", XMLHide, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -4307,20 +4307,20 @@ End; /////////////////////////////////////////////////////////////// /// TStyle /////////////////////////////////////////////////////////////// -type TStyle=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xf'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TStyle=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xf'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Border := new TBorders(self, 'border'); Font := new TFont(self, 'font'); NumberFormat := new TNumFmts(self, 'numFmt'); @@ -4341,13 +4341,13 @@ type TStyle=class(NodeInfo) Protection.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Border','name':Border.NodeName,'obj':Border,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TBorders') ,('field':'Font','name':Font.NodeName,'obj':Font,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TFont') ,('field':'NumberFormat','name':NumberFormat.NodeName,'obj':NumberFormat,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TNumFmts') @@ -4371,20 +4371,20 @@ End; /////////////////////////////////////////////////////////////// /// TXf /////////////////////////////////////////////////////////////// -type TXf=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'xf'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TXf=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'xf'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Alignment := new TAlignment(self, 'alignment'); Protection := new TProtection(self, 'protection'); //TODO... @@ -4397,13 +4397,13 @@ type TXf=class(NodeInfo) Protection.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("NumFmtId", "numFmtId", NumFmtId, ""),("FontId", "fontId", FontId, ""),("FillId", "fillId", FillId, ""),("BorderId", "borderId", BorderId, ""),("XfId", "xfId", XfId, ""),("ApplyFont", "applyFont", ApplyFont, ""),("ApplyFill", "applyFill", ApplyFill, ""),("ApplyBorder", "applyBorder", ApplyBorder, ""),("ApplyAlignment", "applyAlignment", ApplyAlignment, ""),("ApplyProtection", "applyProtection", ApplyProtection, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Alignment','name':Alignment.NodeName,'obj':Alignment,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TAlignment') ,('field':'Protection','name':Protection.NodeName,'obj':Protection,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TProtection') ) union ExtNodes; @@ -4429,20 +4429,20 @@ End; /////////////////////////////////////////////////////////////// /// THeaderFooter /////////////////////////////////////////////////////////////// -type THeaderFooter=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'headerFooter'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type THeaderFooter=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'headerFooter'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4451,13 +4451,13 @@ type THeaderFooter=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("DifferentOddEven", "differentOddEven", DifferentOddEven, ""),("DifferentFirst", "differentFirst", DifferentFirst, ""),("ScaleWithDoc", "scaleWithDoc", ScaleWithDoc, ""),("AlignWithMargin", "alignWithMargins", AlignWithMargin, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'OddHeader','name':'oddHeader','obj':OddHeader,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'OddFooter','name':'oddFooter','obj':OddFooter,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'EvenHeader','name':'evenHeader','obj':EvenHeader,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') @@ -4485,20 +4485,20 @@ End; /////////////////////////////////////////////////////////////// /// TMargins /////////////////////////////////////////////////////////////// -type TMargins=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pageMargins'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TMargins=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pageMargins'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4585,13 +4585,13 @@ type TMargins=class(NodeInfo) XMLFooter := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Left", "left", XMLLeft, ""),("Right", "right", XMLRight, ""),("Top", "top", XMLTop, ""),("Bottom", "bottom", XMLBottom, ""),("Header", "header", XMLHeader, ""),("Footer", "footer", XMLFooter, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -4609,20 +4609,20 @@ End; /////////////////////////////////////////////////////////////// /// THyperLink /////////////////////////////////////////////////////////////// -type THyperLink=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'hyperlink'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type THyperLink=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'hyperlink'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4683,13 +4683,13 @@ type THyperLink=class(NodeInfo) XMLLocation := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("LinkType", "linkType", LinkType, ""),("LinkUrl", "linkUrl", XMLLinkUrl, ""),("Axis", "ref", Axis, ""),("Display", "display", XMLDisplay, ""),("Tooltip", "tooltip", XMLTooltip, ""),("RId", "r:id", RId, ""),("Location", "location", XMLLocation, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -4708,20 +4708,20 @@ End; /////////////////////////////////////////////////////////////// /// TSheetView /////////////////////////////////////////////////////////////// -type TSheetView=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'sheetView'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSheetView=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'sheetView'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4821,13 +4821,13 @@ type TSheetView=class(NodeInfo) XMLWorkbookViewId := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("ShowGridLines", "showGridLines", XMLShowGridLines, ""),("ShowRowColHeaders", "showRowColHeaders", XMLShowRowColHeaders, ""),("TabSelected", "tabSelected", XMLTabSelected, ""),("View", "view", XMLView, ""),("ZoomScale", "zoomScale", XMLZoomScale, ""),("ZoomScaleNormal", "zoomScaleNormal", XMLZoomScaleNormal, ""),("WorkbookViewId", "workbookViewId", XMLWorkbookViewId, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -4846,20 +4846,20 @@ End; /////////////////////////////////////////////////////////////// /// TPane /////////////////////////////////////////////////////////////// -type TPane=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pane'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPane=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pane'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -4933,13 +4933,13 @@ type TPane=class(NodeInfo) XMLState := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("XSplit", "xSplit", XMLXSplit, ""),("YSplit", "ySplit", XMLYSplit, ""),("TopLeftCell", "topLeftCell", XMLTopLeftCell, ""),("ActivePane", "activePane", XMLActivePane, ""),("State", "state", XMLState, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -4956,20 +4956,20 @@ End; /////////////////////////////////////////////////////////////// /// TSelection /////////////////////////////////////////////////////////////// -type TSelection=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'selection'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSelection=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'selection'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5017,13 +5017,13 @@ type TSelection=class(NodeInfo) XMLSqref := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Pane", "pane", XMLPane, ""),("ActiveCell", "activeCell", XMLActiveCell, ""),("Sqref", "sqref", XMLSqref, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -5038,20 +5038,20 @@ End; /////////////////////////////////////////////////////////////// /// TPageLayout /////////////////////////////////////////////////////////////// -type TPageLayout=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pageSetup'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPageLayout=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pageSetup'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5060,13 +5060,13 @@ type TPageLayout=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("PaperSize", "paperSize", PaperSize, ""),("Scale", "scale", Scale, ""),("FitToWidth", "fitToWidth", FitToWidth, ""),("FitToHeight", "fitToHeight", FitToHeight, ""),("UseFirstPageNumber", "cellComments", UseFirstPageNumber, ""),("FirstPageNumber", "firstPageNumber", FirstPageNumber, ""),("PageOrder", "pageOrder", PageOrder, ""),("Orientation", "orientation", Orientation, ""),("BlackAndWhite", "blackAndWhite", BlackAndWhite, ""),("Draft", "draft", Draft, ""),("CellComments", "cellComments", CellComments, ""),("CellError", "errors", CellError, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -5090,20 +5090,20 @@ End; /////////////////////////////////////////////////////////////// /// TAppProperty /////////////////////////////////////////////////////////////// -type TAppProperty=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'Properties'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TAppProperty=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'Properties'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5242,13 +5242,13 @@ type TAppProperty=class(NodeInfo) XMLVersion := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Application','name':'Application','obj':XMLApplication,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'DocSecurity','name':'DocSecurity','obj':XMLDocSecurity,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'ScaleCrop','name':'ScaleCrop','obj':XMLScaleCrop,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') @@ -5280,20 +5280,20 @@ End; /////////////////////////////////////////////////////////////// /// TCoreProperty /////////////////////////////////////////////////////////////// -type TCoreProperty=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'cp:coreProperties'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TCoreProperty=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'cp:coreProperties'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5445,13 +5445,13 @@ type TCoreProperty=class(NodeInfo) XMLContentStatus := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Title','name':'dc:title','obj':XMLTitle,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'Subject','name':'dc:subject','obj':XMLSubject,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') ,('field':'Creator','name':'dc:creator','obj':XMLCreator,'attrEx':'','nodeType':'pcdata','attrName':'', 'desc':'', 'class':'') @@ -5485,20 +5485,20 @@ End; /////////////////////////////////////////////////////////////// /// TBr /////////////////////////////////////////////////////////////// -type TBr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:br'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TBr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:br'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5507,13 +5507,13 @@ type TBr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Type", "w:type", Type, ""),("Clear", "w:left", Clear, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -5527,20 +5527,20 @@ End; /////////////////////////////////////////////////////////////// /// TwFont /////////////////////////////////////////////////////////////// -type TwFont=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:rFonts'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwFont=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:rFonts'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5666,13 +5666,13 @@ type TwFont=class(NodeInfo) XMLcsTheme := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("eastAsia", "w:eastAsia", XMLeastAsia, "东亚字体"),("eastAsiaTheme", "w:eastAsiaTheme", XMLeastAsiaTheme, "东亚主题字体"),("hAnsi", "w:hAnsi", XMLhAnsi, "Unicode范围内的所有字符(该范围不属于上面定义的三个类别之一)字体."),("hAnsiTheme", "w:hAnsiTheme", XMLhAnsiTheme, "Unicode范围内的所有字符(该范围不属于上面定义的三个类别之一)主题字体. "),("hint", "w:hint", XMLhint, "指定用于设置当前运行中任何不明确字符格式的字体类型."),("ascii", "w:ascii", XMLascii, "ASCII range (0 - 127) 字体."),("asciiTheme", "w:asciiTheme", XMLasciiTheme, "ASCII range (0 - 127) 主题字体."),("cs", "w:cs", XMLcs, "字体:格式化复杂脚本Unicode范围内的所有字符."),("csTheme", "w:csTheme", XMLcsTheme, "主题字体:格式化复杂脚本Unicode范围内的所有字符. ")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -5693,20 +5693,20 @@ End; /////////////////////////////////////////////////////////////// /// TwrPr /////////////////////////////////////////////////////////////// -type TwrPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:rPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwrPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:rPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin rFont := new TwFont(self, 'w:rFonts'); Bdr := new TwBorder(self, 'w:bdr'); Shading := new TwShading(self, 'w:shd'); @@ -5723,13 +5723,13 @@ type TwrPr=class(NodeInfo) Del.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'rFont','name':rFont.NodeName,'obj':rFont,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwFont') ,('field':'Bdr','name':Bdr.NodeName,'obj':Bdr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwBorder') ,('field':'Shading','name':Shading.NodeName,'obj':Shading,'attrEx':'','nodeType':'','attrName':'', 'desc':'底纹', 'class':'TwShading') @@ -5772,31 +5772,31 @@ type TwrPr=class(NodeInfo) ) union ExtNodes; End; - Property Name write writeName; - Function writeName(n); - Begin - SetName(n, false); - End; - - Function SetName(n, isUtf8); - Begin - nName := n; - if not isUtf8 then - nName := class(TSXml).CurCodePageToUtf8(n); - rFont.XMLcs := nName; - rFont.XMLeastAsia := nName; - rFont.XMLhAnsi := nName; - rFont.XMLascii := nName; - End; - - Property Size read readSize write writeSize; - Function writeSize(n); - Begin - Sz := n * 2; - End; - Function readSize(); - Begin - return Value("Sz") / 2; + Property Name write writeName; + Function writeName(n); + Begin + SetName(n, false); + End; + + Function SetName(n, isUtf8); + Begin + nName := n; + if not isUtf8 then + nName := class(TSXml).CurCodePageToUtf8(n); + rFont.XMLcs := nName; + rFont.XMLeastAsia := nName; + rFont.XMLhAnsi := nName; + rFont.XMLascii := nName; + End; + + Property Size read readSize write writeSize; + Function writeSize(n); + Begin + Sz := n * 2; + End; + Function readSize(); + Begin + return Value("Sz") / 2; End; //Attributes @@ -5846,20 +5846,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumPr /////////////////////////////////////////////////////////////// -type TNumPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:numPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:numPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5868,13 +5868,13 @@ type TNumPr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Level','name':'w:ilvl','obj':Level,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'项目层级', 'class':'') ,('field':'numId','name':'w:numId','obj':numId,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'项目编号ID', 'class':'') ) union ExtNodes; @@ -5890,20 +5890,20 @@ End; /////////////////////////////////////////////////////////////// /// TTextBoxImpl /////////////////////////////////////////////////////////////// -type TTextBoxImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:txbxContent'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTextBoxImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:txbxContent'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin P := new TParagraphImpl(self, 'P'); //TODO... End; @@ -5914,13 +5914,13 @@ type TTextBoxImpl=class(NodeInfo) P.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'P','name':P.NodeName,'obj':P,'attrEx':'','nodeType':'','attrName':'', 'desc':'disable', 'class':'TParagraphImpl') ) union ExtNodes; End; @@ -5934,20 +5934,20 @@ End; /////////////////////////////////////////////////////////////// /// TWHyperLinkImpl /////////////////////////////////////////////////////////////// -type TWHyperLinkImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:hyperlink'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TWHyperLinkImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:hyperlink'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -5956,13 +5956,13 @@ type TWHyperLinkImpl=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Anchor", "w:anchor", Anchor, ""),("History", "w:history", History, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -5976,20 +5976,20 @@ End; /////////////////////////////////////////////////////////////// /// TwpPr /////////////////////////////////////////////////////////////// -type TwpPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:pPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwpPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:pPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin NumPr := new TNumPr(self, 'w:numPr'); Tabs := new TTabStops(self, 'w:tabs'); rPr := new TwrPr(self, 'w:rPr'); @@ -6012,13 +6012,13 @@ type TwpPr=class(NodeInfo) SectPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'StyleId','name':'w:pStyle','obj':StyleId,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'段落样式ID', 'class':'') ,('field':'NumPr','name':NumPr.NodeName,'obj':NumPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'项目编号、数字编号', 'class':'TNumPr') ,('field':'Alignment','name':'w:jc','obj':Alignment,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'左、右、居中和对齐', 'class':'') @@ -6126,20 +6126,20 @@ End; /////////////////////////////////////////////////////////////// /// TcNvGraphicFramePr /////////////////////////////////////////////////////////////// -type TcNvGraphicFramePr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'wp:TcNvGraphicFramePr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcNvGraphicFramePr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'wp:TcNvGraphicFramePr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -6148,13 +6148,13 @@ type TcNvGraphicFramePr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'noChangeAspect','name':'a:graphicFrameLocks','obj':noChangeAspect,'attrEx':'noChangeAspect','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'xmlns','name':'a:graphicFrameLocks','obj':xmlns,'attrEx':'xmlns:a','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; @@ -6170,20 +6170,20 @@ End; /////////////////////////////////////////////////////////////// /// TnvPicPr /////////////////////////////////////////////////////////////// -type TnvPicPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pic:nvPicPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TnvPicPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pic:nvPicPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin CNvPr := new TCNvPr(self, 'pic:cNvPr'); CNvPicPr := new TcNvPicPr(self, 'xdr:cNvPicPr'); //TODO... @@ -6196,13 +6196,13 @@ type TnvPicPr=class(NodeInfo) CNvPicPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'CNvPr','name':CNvPr.NodeName,'obj':CNvPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TCNvPr') ,('field':'CNvPicPr','name':CNvPicPr.NodeName,'obj':CNvPicPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TcNvPicPr') ,('field':'CNvSpPr','name':'xdr:cNvSpPr','obj':CNvSpPr,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') @@ -6220,20 +6220,20 @@ End; /////////////////////////////////////////////////////////////// /// TCNvPr /////////////////////////////////////////////////////////////// -type TCNvPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pic:cNvPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TCNvPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pic:cNvPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin ExtLst := new TExtLst(self, 'a:extLst'); //TODO... End; @@ -6244,13 +6244,13 @@ type TCNvPr=class(NodeInfo) ExtLst.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("ID", "id", ID, ""),("Name", "name", Name, ""),("Descr", "descr", Descr, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'ExtLst','name':ExtLst.NodeName,'obj':ExtLst,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TExtLst') ) union ExtNodes; End; @@ -6267,20 +6267,20 @@ End; /////////////////////////////////////////////////////////////// /// TExtLst /////////////////////////////////////////////////////////////// -type TExtLst=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:extLst'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TExtLst=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:extLst'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Ext := new TAext(self, 'a:ext'); //TODO... End; @@ -6291,13 +6291,13 @@ type TExtLst=class(NodeInfo) Ext.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Ext','name':Ext.NodeName,'obj':Ext,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TAext') ) union ExtNodes; End; @@ -6311,20 +6311,20 @@ End; /////////////////////////////////////////////////////////////// /// TAext /////////////////////////////////////////////////////////////// -type TAext=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:ext'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TAext=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:ext'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -6333,13 +6333,13 @@ type TAext=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Uri", "uri", Uri, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Xmlns16','name':'a16:creationId','obj':Xmlns16,'attrEx':'xmlns:a16','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Id','name':'a16:creationId','obj':Id,'attrEx':'id','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; @@ -6356,20 +6356,20 @@ End; /////////////////////////////////////////////////////////////// /// TprstGeom /////////////////////////////////////////////////////////////// -type TprstGeom=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:prstGeom'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TprstGeom=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:prstGeom'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -6378,13 +6378,13 @@ type TprstGeom=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Prst", "prst", Prst, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'AvLst','name':'a:avLst','obj':AvLst,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -6399,20 +6399,20 @@ End; /////////////////////////////////////////////////////////////// /// TblipFill /////////////////////////////////////////////////////////////// -type TblipFill=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pic:blipFill'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TblipFill=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pic:blipFill'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Blip := new TBlip(self, 'a:blip'); Stretch := new TStretch(self, 'a:stretch'); //TODO... @@ -6425,13 +6425,13 @@ type TblipFill=class(NodeInfo) Stretch.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Blip','name':Blip.NodeName,'obj':Blip,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TBlip') ,('field':'Stretch','name':Stretch.NodeName,'obj':Stretch,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TStretch') ) union ExtNodes; @@ -6447,20 +6447,20 @@ End; /////////////////////////////////////////////////////////////// /// TwLine /////////////////////////////////////////////////////////////// -type TwLine=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:ln'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwLine=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:ln'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SolidFill := new TSolidFill(self, 'a:solidFill'); //TODO... End; @@ -6471,13 +6471,13 @@ type TwLine=class(NodeInfo) SolidFill.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'SolidFill','name':SolidFill.NodeName,'obj':SolidFill,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSolidFill') ) union ExtNodes; End; @@ -6491,20 +6491,20 @@ End; /////////////////////////////////////////////////////////////// /// TpicsPpr /////////////////////////////////////////////////////////////// -type TpicsPpr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pic:spPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TpicsPpr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pic:spPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin XFrm := new TXfrm(self, 'a:xfrm'); PrstGeom := new TprstGeom(self, 'a:prstGeom'); Line := new TwLine(self, 'a:ln'); @@ -6519,13 +6519,13 @@ type TpicsPpr=class(NodeInfo) Line.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'XFrm','name':XFrm.NodeName,'obj':XFrm,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TXfrm') ,('field':'PrstGeom','name':PrstGeom.NodeName,'obj':PrstGeom,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TprstGeom') ,('field':'Line','name':Line.NodeName,'obj':Line,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwLine') @@ -6543,20 +6543,20 @@ End; /////////////////////////////////////////////////////////////// /// TBlip /////////////////////////////////////////////////////////////// -type TBlip=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:blip'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TBlip=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:blip'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -6565,13 +6565,13 @@ type TBlip=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Xmlns", "xmlns:r", Xmlns, ""),("Embed", "r:embed", Embed, ""),("Cstate", "cstate", Cstate, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -6586,20 +6586,20 @@ End; /////////////////////////////////////////////////////////////// /// TStretch /////////////////////////////////////////////////////////////// -type TStretch=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:stretch'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TStretch=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:stretch'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -6608,13 +6608,13 @@ type TStretch=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'FillRect','name':'a:fillRect','obj':FillRect,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -6628,20 +6628,20 @@ End; /////////////////////////////////////////////////////////////// /// TRef /////////////////////////////////////////////////////////////// -type TRef=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:stretch'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TRef=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:stretch'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin SchemeClr := new TScheme(self, 'a:schemeClr'); //TODO... End; @@ -6652,13 +6652,13 @@ type TRef=class(NodeInfo) SchemeClr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Idx", "idx", Idx, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'SchemeClr','name':SchemeClr.NodeName,'obj':SchemeClr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TScheme') ) union ExtNodes; End; @@ -6673,20 +6673,20 @@ End; /////////////////////////////////////////////////////////////// /// TScheme /////////////////////////////////////////////////////////////// -type TScheme=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:schemeClr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TScheme=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:schemeClr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -6695,13 +6695,13 @@ type TScheme=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Val", "val", Val, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Shade','name':'a:shade','obj':Shade,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -6716,20 +6716,20 @@ End; /////////////////////////////////////////////////////////////// /// TXdrStyle /////////////////////////////////////////////////////////////// -type TXdrStyle=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:stretch'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TXdrStyle=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:stretch'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin LnRef := new TRef(self, 'a:lnRef'); FillRef := new TRef(self, 'a:fillRef'); EffectRef := new TRef(self, 'a:effectRef'); @@ -6746,13 +6746,13 @@ type TXdrStyle=class(NodeInfo) FontRef.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'LnRef','name':LnRef.NodeName,'obj':LnRef,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TRef') ,('field':'FillRef','name':FillRef.NodeName,'obj':FillRef,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TRef') ,('field':'EffectRef','name':EffectRef.NodeName,'obj':EffectRef,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TRef') @@ -6772,20 +6772,20 @@ End; /////////////////////////////////////////////////////////////// /// TPic /////////////////////////////////////////////////////////////// -type TPic=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'pic:pic'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPic=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'pic:pic'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin NvPicPr := new TnvPicPr(self, 'pic:nvPicPr'); BlipFill := new TblipFill(self, 'pic:blipFill'); SpPr := new TSpPr(self, 'pic:spPr'); @@ -6804,13 +6804,13 @@ type TPic=class(NodeInfo) TxBody.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Macro", "macro", Macro, ""),("Textlink", "textlink", Textlink, ""),("Xmlns", "xmlns:pic", Xmlns, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'NvPicPr','name':NvPicPr.NodeName,'obj':NvPicPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TnvPicPr') ,('field':'BlipFill','name':BlipFill.NodeName,'obj':BlipFill,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TblipFill') ,('field':'SpPr','name':SpPr.NodeName,'obj':SpPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSpPr') @@ -6835,20 +6835,20 @@ End; /////////////////////////////////////////////////////////////// /// TGraphicData /////////////////////////////////////////////////////////////// -type TGraphicData=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:graphicData'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TGraphicData=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:graphicData'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Pic := new TPic(self, 'pic:pic'); //TODO... End; @@ -6859,13 +6859,13 @@ type TGraphicData=class(NodeInfo) Pic.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("uri", "uri", uri, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'C','name':'c:chart','obj':C,'attrEx':'xmlns:c','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'R','name':'c:chart','obj':R,'attrEx':'xmlns:r','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Rid','name':'c:chart','obj':Rid,'attrEx':'r:id','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -6886,20 +6886,20 @@ End; /////////////////////////////////////////////////////////////// /// TGraphic /////////////////////////////////////////////////////////////// -type TGraphic=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'a:graphic'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TGraphic=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'a:graphic'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin GraphicData := new TGraphicData(self, 'a:graphicData'); //TODO... End; @@ -6910,13 +6910,13 @@ type TGraphic=class(NodeInfo) GraphicData.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("xmlns", "xmlns:a", xmlns, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'GraphicData','name':GraphicData.NodeName,'obj':GraphicData,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TGraphicData') ) union ExtNodes; End; @@ -6931,20 +6931,20 @@ End; /////////////////////////////////////////////////////////////// /// TwInline /////////////////////////////////////////////////////////////// -type TwInline=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'wp:inline'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwInline=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'wp:inline'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin cNvGraphicFramePr := new TcNvGraphicFramePr(self, 'wp:cNvGraphicFramePr'); Graphic := new TGraphic(self, 'a:graphic'); //TODO... @@ -6957,13 +6957,13 @@ type TwInline=class(NodeInfo) Graphic.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("distT", "distT", distT, ""),("distB", "distB", distB, ""),("distL", "distL", distL, ""),("distR", "distR", distR, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'cx','name':'wp:extent','obj':cx,'attrEx':'cx','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'cy','name':'wp:extent','obj':cy,'attrEx':'cy','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'l','name':'wp:effectExtent','obj':l,'attrEx':'l','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -7001,20 +7001,20 @@ End; /////////////////////////////////////////////////////////////// /// TwDrawing /////////////////////////////////////////////////////////////// -type TwDrawing=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:drawing'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwDrawing=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:drawing'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin WInline := new TwInline(self, 'wp:inline'); //TODO... End; @@ -7025,13 +7025,13 @@ type TwDrawing=class(NodeInfo) WInline.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'WInline','name':WInline.NodeName,'obj':WInline,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwInline') ) union ExtNodes; End; @@ -7045,20 +7045,20 @@ End; /////////////////////////////////////////////////////////////// /// TText /////////////////////////////////////////////////////////////// -type TText=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:t'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TText=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:t'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7067,13 +7067,13 @@ type TText=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Space", "xml:space", Space, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Text','name':'Text','obj':Text,'attrEx':'','nodeType':'tcdata','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -7088,20 +7088,20 @@ End; /////////////////////////////////////////////////////////////// /// TRunImpl /////////////////////////////////////////////////////////////// -type TRunImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:r'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TRunImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:r'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin rPr := new TwrPr(self, 'w:rPr'); Br := new TBr(self, 'w:br'); Drawing := new TwDrawing(self, 'w:drawing'); @@ -7116,13 +7116,13 @@ type TRunImpl=class(NodeInfo) Drawing.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("xmlns", "xmlns:w", xmlns, ""),("rsidR", "w:rsidR", rsidR, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'rPr','name':rPr.NodeName,'obj':rPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'字体属性', 'class':'TwrPr') ,('field':'fldCharType','name':'w:fldChar','obj':fldCharType,'attrEx':'w:fldCharType','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Dirty','name':'w:fldChar','obj':Dirty,'attrEx':'w:dirty','nodeType':'','attrName':'', 'desc':'', 'class':'') @@ -7162,20 +7162,20 @@ End; /////////////////////////////////////////////////////////////// /// TFootnoteImpl /////////////////////////////////////////////////////////////// -type TFootnoteImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:footnote'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TFootnoteImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:footnote'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7184,13 +7184,13 @@ type TFootnoteImpl=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Type", "w:type", Type, ""),("Id", "w:id", Id, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7204,20 +7204,20 @@ End; /////////////////////////////////////////////////////////////// /// TFootnoteBody /////////////////////////////////////////////////////////////// -type TFootnoteBody=class(NodeInfo, TFootnotes) - Function Create(); overload; - Begin - Create(nil, 'w:footnote'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TFootnoteBody=class(NodeInfo, TFootnotes) + Function Create(); overload; + Begin + Create(nil, 'w:footnote'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7226,13 +7226,13 @@ type TFootnoteBody=class(NodeInfo, TFootnotes) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7244,20 +7244,20 @@ End; /////////////////////////////////////////////////////////////// /// TBookMark /////////////////////////////////////////////////////////////// -type TBookMark=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:bookmarkStart'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TBookMark=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:bookmarkStart'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7266,13 +7266,13 @@ type TBookMark=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("name", "w:name", name, ""),("id", "w:id", id, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7286,20 +7286,20 @@ End; /////////////////////////////////////////////////////////////// /// TFldSimple /////////////////////////////////////////////////////////////// -type TFldSimple=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:fldSimple'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TFldSimple=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:fldSimple'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Run := new TRun(self, 'w:r'); //TODO... End; @@ -7310,13 +7310,13 @@ type TFldSimple=class(NodeInfo) Run.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("instr", "w:instr", instr, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Run','name':Run.NodeName,'obj':Run,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TRun') ) union ExtNodes; End; @@ -7331,20 +7331,20 @@ End; /////////////////////////////////////////////////////////////// /// TParagraphImpl /////////////////////////////////////////////////////////////// -type TParagraphImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:p'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TParagraphImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:p'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin pPr := new TwpPr(self, 'w:pPr'); markStart := new TBookMark(self, 'w:bookmarkStart'); Run := new TRun(self, 'w:r'); @@ -7361,13 +7361,13 @@ type TParagraphImpl=class(NodeInfo) markEnd.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'pPr','name':pPr.NodeName,'obj':pPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'段落格式', 'class':'TwpPr') ,('field':'markStart','name':markStart.NodeName,'obj':markStart,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TBookMark') ,('field':'Run','name':Run.NodeName,'obj':Run,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TRun') @@ -7387,20 +7387,20 @@ End; /////////////////////////////////////////////////////////////// /// TwBody /////////////////////////////////////////////////////////////// -type TwBody=class(NodeInfo, TDocumentBody) - Function Create(); overload; - Begin - Create(nil, 'w:body'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwBody=class(NodeInfo, TDocumentBody) + Function Create(); overload; + Begin + Create(nil, 'w:body'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin ps := array(); //TODO... End; @@ -7410,13 +7410,13 @@ type TwBody=class(NodeInfo, TDocumentBody) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'ps','name':'w:p','obj':ps,'attrEx':'','nodeType':'','attrName':'','arrObj':'array', 'desc':'', 'class':'TParagraphImpl') ) union ExtNodes; End; @@ -7430,20 +7430,20 @@ End; /////////////////////////////////////////////////////////////// /// TOptInfo /////////////////////////////////////////////////////////////// -type TOptInfo=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:cellDel'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TOptInfo=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:cellDel'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7465,13 +7465,13 @@ type TOptInfo=class(NodeInfo) XMLAuthor := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Author", "w:author", XMLAuthor, "作者"),("Date", "w:date", Date, "修改日期"),("ID", "w:id", ID, "disable")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7486,20 +7486,20 @@ End; /////////////////////////////////////////////////////////////// /// TRevisionImpl /////////////////////////////////////////////////////////////// -type TRevisionImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:del'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TRevisionImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:del'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7521,13 +7521,13 @@ type TRevisionImpl=class(NodeInfo) XMLAuthor := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Author", "w:author", XMLAuthor, "作者"),("Date", "w:date", Date, "修改日期"),("ID", "w:id", ID, "disable")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7542,20 +7542,20 @@ End; /////////////////////////////////////////////////////////////// /// TDocCommentImpl /////////////////////////////////////////////////////////////// -type TDocCommentImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:comment'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TDocCommentImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:comment'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin P := new TParagraphImpl(self, 'w:p'); //TODO... End; @@ -7579,13 +7579,13 @@ type TDocCommentImpl=class(NodeInfo) XMLAuthor := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Author", "w:author", XMLAuthor, "作者"),("Date", "w:date", Date, "修改日期"),("ID", "w:id", ID, "disable")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'P','name':P.NodeName,'obj':P,'attrEx':'','nodeType':'','attrName':'', 'desc':'disable', 'class':'TParagraphImpl') ) union ExtNodes; End; @@ -7602,20 +7602,20 @@ End; /////////////////////////////////////////////////////////////// /// TCol /////////////////////////////////////////////////////////////// -type TCol=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:cols'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TCol=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:cols'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7624,13 +7624,13 @@ type TCol=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("W", "w:w", W, "Column Width"),("space", "w:space", space, "Space Before Following Column")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7644,20 +7644,20 @@ End; /////////////////////////////////////////////////////////////// /// TColsImpl /////////////////////////////////////////////////////////////// -type TColsImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:cols'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TColsImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:cols'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin col := array(); //TODO... End; @@ -7667,13 +7667,13 @@ type TColsImpl=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("equalWidth", "w:equalWidth", equalWidth, "Equal Column Widths"),("num", "w:num", num, "Number of Equal Width Columns"),("sep", "w:sep", sep, "Draw Line Between Columns"),("space", "w:space", space, "Spacing Between Equal Width Columns")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'col','name':'w:col','obj':col,'attrEx':'','nodeType':'','attrName':'','arrObj':'array', 'desc':'Column Definitions', 'class':'TCol') ) union ExtNodes; End; @@ -7691,20 +7691,20 @@ End; /////////////////////////////////////////////////////////////// /// TPageMargin /////////////////////////////////////////////////////////////// -type TPageMargin=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:pgMar'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPageMargin=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:pgMar'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7713,13 +7713,13 @@ type TPageMargin=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("gutter", "w:gutter", gutter, "当前节中每页的页边距."),("footer", "w:footer", footer, "指定从页面底部边缘到页脚底部边缘的距离(以二十分之一点为单位)."),("header", "w:header", header, "指定从页面上边缘到页眉上边缘的距离(以二十分之一为单位)."),("left", "w:left", left, "指定页面左边缘与此文档文本范围左边缘之间的距离(以点的二十分之一为单位)."),("bottom", "w:bottom", bottom, "指定主文档的文本页边距底部与本节中所有页面的页面底部之间的距离(以二十分之一为单位)."),("right", "w:right", right, "指定页面右边缘与此文档文本范围右边缘之间的距离(以点的二十分之一为单位)."),("top", "w:top", top, "指定主文档的文本页边距顶部与本节中所有页面的页面顶部之间的距离(以二十分之一为单位).")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7738,20 +7738,20 @@ End; /////////////////////////////////////////////////////////////// /// TDocGrid /////////////////////////////////////////////////////////////// -type TDocGrid=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:docGrid'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TDocGrid=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:docGrid'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7760,13 +7760,13 @@ type TDocGrid=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("charSpace", "w:charSpace", charSpace, "字符间距"),("charSize", "w:charSize", charSize, "文档网格字符间距"),("linePitch", "w:linePitch", linePitch, "文档网格线间距"),("Type", "w:type", Type, "文档网格线类型")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7782,20 +7782,20 @@ End; /////////////////////////////////////////////////////////////// /// TReference /////////////////////////////////////////////////////////////// -type TReference=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:headerReference'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TReference=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:headerReference'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7804,13 +7804,13 @@ type TReference=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Type", "w:type", Type, ""),("ID", "r:id", ID, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7824,20 +7824,20 @@ End; /////////////////////////////////////////////////////////////// /// TPageBorders /////////////////////////////////////////////////////////////// -type TPageBorders=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:pgBorders'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPageBorders=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:pgBorders'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Top := new TwBorder(self, 'w:top'); Left := new TwBorder(self, 'w:left'); Bottom := new TwBorder(self, 'w:bottom'); @@ -7854,13 +7854,13 @@ type TPageBorders=class(NodeInfo) Right.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("offsetFrom", "w:offsetFrom", offsetFrom, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Top','name':Top.NodeName,'obj':Top,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') ,('field':'Left','name':Left.NodeName,'obj':Left,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') ,('field':'Bottom','name':Bottom.NodeName,'obj':Bottom,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') @@ -7881,20 +7881,20 @@ End; /////////////////////////////////////////////////////////////// /// TPage /////////////////////////////////////////////////////////////// -type TPage=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:pgSz'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPage=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:pgSz'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -7903,13 +7903,13 @@ type TPage=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Code", "w:code", Code, "纸张类型(指定打印机特定的纸张代码)."),("Height", "w:h", Height, "当前节中所有页面的高度(以二十分之一点为单位)."),("Width", "w:w", Width, "此属性表示当前节中所有页面的宽度(以二十分之一为单位)."),("Orient ", "w:orient ", Orient , "指定此节中所有页面的方向.")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -7925,20 +7925,20 @@ End; /////////////////////////////////////////////////////////////// /// TDocSectionImpl /////////////////////////////////////////////////////////////// -type TDocSectionImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:sectPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TDocSectionImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:sectPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Header := new TReference(self, 'w:headerReference'); Footer := new TReference(self, 'w:footerReference'); cols := new TCols(self, 'w:cols'); @@ -7961,13 +7961,13 @@ type TDocSectionImpl=class(NodeInfo) Borders.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Header','name':Header.NodeName,'obj':Header,'attrEx':'','nodeType':'','attrName':'', 'desc':'disable', 'class':'TReference') ,('field':'Footer','name':Footer.NodeName,'obj':Footer,'attrEx':'','nodeType':'','attrName':'', 'desc':'disable', 'class':'TReference') ,('field':'bidi','name':'w:bidi','obj':bidi,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'章节从右到左的布局', 'class':'') @@ -8003,20 +8003,20 @@ End; /////////////////////////////////////////////////////////////// /// TcellMerge /////////////////////////////////////////////////////////////// -type TcellMerge=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:cellMerge'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TcellMerge=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:cellMerge'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8038,13 +8038,13 @@ type TcellMerge=class(NodeInfo) XMLAuthor := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Author", "w:author", XMLAuthor, ""),("Date", "w:date", Date, ""),("ID", "w:id", ID, ""),("vmerge", "w:vmerge", vmerge, "垂直合并设置。"),("vmergeOrig", "w:vmergeOrig", vmergeOrig, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8061,20 +8061,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTcPr /////////////////////////////////////////////////////////////// -type TwTcPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tcPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTcPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tcPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Shading := new TwShading(self, 'w:shd'); cnfStyle := new TwCnfStyle(self, 'w:cnfStyle'); CellMar := new TTblCellMar(self, 'w:tcMar'); @@ -8097,13 +8097,13 @@ type TwTcPr=class(NodeInfo) cellMerge.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Width','name':'w:tcW','obj':Width,'attrEx':'w:w','nodeType':'','attrName':'', 'desc':'表格单元格宽度', 'class':'') ,('field':'Type','name':'w:tcW','obj':Type,'attrEx':'w:type','nodeType':'','attrName':'', 'desc':'宽度属性的单位。此属性用于定义表格的各种属性,包括:单元格间距、首选宽度和表格边距。', 'class':'') ,('field':'Shading','name':Shading.NodeName,'obj':Shading,'attrEx':'','nodeType':'','attrName':'', 'desc':'表头底纹', 'class':'TwShading') @@ -8149,20 +8149,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTc /////////////////////////////////////////////////////////////// -type TwTc=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tc'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTc=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tc'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin TcPr := new TwTcPr(self, 'w:tcPr'); P := new TParagraphImpl(self, 'w:p'); //TODO... @@ -8175,13 +8175,13 @@ type TwTc=class(NodeInfo) P.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'TcPr','name':TcPr.NodeName,'obj':TcPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwTcPr') ,('field':'P','name':P.NodeName,'obj':P,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TParagraphImpl') ) union ExtNodes; @@ -8197,20 +8197,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTrPr /////////////////////////////////////////////////////////////// -type TwTrPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:trPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTrPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:trPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin cnfStyle := new TwCnfStyle(self, 'w:cnfStyle'); Del := new TOptInfo(self, 'w:del'); //TODO... @@ -8223,13 +8223,13 @@ type TwTrPr=class(NodeInfo) Del.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Height','name':'w:trHeight','obj':Height,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'行高', 'class':'') ,('field':'Rule','name':'w:trHeight','obj':Rule,'attrEx':'w:hRule','nodeType':'','attrName':'', 'desc':'如果Rule的值为自动,则应根据其内容的高度自动确定表行的高度,忽略Height值;如果Rule的值至少为least,则表行的高度应至少为Height属性的值;如果Rule的值是精确的,那么表行的高度应该正好是Height属性的值。', 'class':'') ,('field':'Alignment','name':'w:jc','obj':Alignment,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'对齐方式(left、right、center)', 'class':'') @@ -8261,20 +8261,20 @@ End; /////////////////////////////////////////////////////////////// /// TwCnfStyle /////////////////////////////////////////////////////////////// -type TwCnfStyle=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:cnfStyle'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwCnfStyle=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:cnfStyle'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8283,13 +8283,13 @@ type TwCnfStyle=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Val", "w:val", Val, ""),("FirstRow", "w:firstRow", FirstRow, "首行"),("LastRow", "w:lastRow", LastRow, "末行"),("FirstColumn", "w:firstColumn", FirstColumn, "首列"),("LastColumn", "w:lastColumn", LastColumn, "末列"),("OddVBand", "w:oddVBand", OddVBand, "奇条带列"),("EvenVBand", "w:evenVBand", EvenVBand, "偶条带列"),("OddHBand", "w:oddHBand", OddHBand, "奇条带行"),("EvenHBand", "w:evenHBand", EvenHBand, "偶条带行"),("FirstRowFirstColumn", "w:firstRowFirstColumn", FirstRowFirstColumn, "左上角单元格"),("FirstRowLastColumn", "w:firstRowLastColumn", FirstRowLastColumn, "右上角单元格"),("LastRowFirstColumn", "w:lastRowFirstColumn", LastRowFirstColumn, "左下角单元格"),("LastRowLastColumn", "w:lastRowLastColumn", LastRowLastColumn, "右下角单元格")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8314,20 +8314,20 @@ End; /////////////////////////////////////////////////////////////// /// TwShading /////////////////////////////////////////////////////////////// -type TwShading=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:shd'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwShading=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:shd'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8336,13 +8336,13 @@ type TwShading=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Val", "w:val", Val, "指定用于将图案颜色覆盖在此段落底纹的背景色上的图案。此图案由应用于背景底纹颜色上的遮罩组成,以获得应显示图案颜色的位置。."),("Color", "w:color", Color, "前景颜色: RRGGBB format or auto"),("Fill", "w:fill", Fill, "背景颜色: RRGGBB format or auto"),("ThemeColor", "w:themeColor", ThemeColor, "前景主题颜色: theme color"),("ThemeFill", "w:themeFill", ThemeFill, "背景主题颜色: theme color"),("ThemeFillShade", "w:themeFillShade", ThemeFillShade, "阴影颜色: theme color"),("ThemeFillTint", "w:themeFillTint", ThemeFillTint, "tint 主题填充颜色."),("ThemeShade", "w:themeShade", ThemeShade, "主题阴影颜色."),("ThemeTint", "w:themeTint", ThemeTint, "tint主题阴影颜色.")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8363,20 +8363,20 @@ End; /////////////////////////////////////////////////////////////// /// TTblCellMar /////////////////////////////////////////////////////////////// -type TTblCellMar=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblCellMar'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTblCellMar=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblCellMar'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8385,13 +8385,13 @@ type TTblCellMar=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Top','name':'w:top','obj':Top,'attrEx':'w:w','nodeType':'','attrName':'', 'desc':'表格单元格上边距,指定宽度属性的值.', 'class':'') ,('field':'TopType','name':'w:top','obj':TopType,'attrEx':'w:type','nodeType':'','attrName':'', 'desc':'宽度属性的单位,auto(自动确定的宽度)、dxa(点的二十分之一宽度)nil(无宽度)pct(百分之五十宽度)', 'class':'') ,('field':'Left','name':'w:left','obj':Left,'attrEx':'w:w','nodeType':'','attrName':'', 'desc':'表格单元格左边距,指定宽度属性的值.', 'class':'') @@ -8419,20 +8419,20 @@ End; /////////////////////////////////////////////////////////////// /// TTblPrEx /////////////////////////////////////////////////////////////// -type TTblPrEx=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblPrEx'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTblPrEx=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblPrEx'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Borders := new TwTblBorders(self, 'w:tblBorders'); Shading := new TwShading(self, 'w:shd'); CellMar := new TTblCellMar(self, 'w:tblCellMar'); @@ -8447,13 +8447,13 @@ type TTblPrEx=class(NodeInfo) CellMar.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Alignment','name':'w:jc','obj':Alignment,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'Borders','name':Borders.NodeName,'obj':Borders,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwTblBorders') ,('field':'Shading','name':Shading.NodeName,'obj':Shading,'attrEx':'','nodeType':'','attrName':'', 'desc':'表头底纹', 'class':'TwShading') @@ -8501,20 +8501,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTr /////////////////////////////////////////////////////////////// -type TwTr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin tblPrEx := new TTblPrEx(self, 'w:tblPrEx'); TrPr := new TwTrPr(self, 'w:trPr'); Tc := array(); @@ -8528,13 +8528,13 @@ type TwTr=class(NodeInfo) TrPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'tblPrEx','name':tblPrEx.NodeName,'obj':tblPrEx,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TTblPrEx') ,('field':'TrPr','name':TrPr.NodeName,'obj':TrPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwTrPr') ,('field':'Tc','name':'w:tc','obj':Tc,'attrEx':'','nodeType':'','attrName':'','arrObj':'array', 'desc':'', 'class':'TwTc') @@ -8552,20 +8552,20 @@ End; /////////////////////////////////////////////////////////////// /// TwBorder /////////////////////////////////////////////////////////////// -type TwBorder=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:top'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwBorder=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:top'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8574,13 +8574,13 @@ type TwBorder=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Val", "w:val", Val, "指定边框样式."),("Color", "w:color", Color, "边框颜色."),("ThemeColor", "w:themeColor", ThemeColor, "边框主题颜色."),("ThemeTint", "w:themeTint", ThemeTint, "指定应用于此边框实例提供的主题颜色(如果有)的色调值."),("Size", "w:sz", Size, "边框宽度."),("Frame", "w:frame", Frame, "指定是否应修改指定的边框,以通过将边框外观从离文本最近的边缘反转到离文本最远的边缘来创建框架效果."),("Shadow", "w:shadow", Shadow, "边框阴影."),("Space", "w:space", Space, "放置此边框的间距偏移."),("ThemeShade", "w:themeShade", ThemeShade, "边框阴影的主题颜色."),("bar", "w:bar", bar, "边框属性")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8602,20 +8602,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTblBorders /////////////////////////////////////////////////////////////// -type TwTblBorders=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblBorders'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTblBorders=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblBorders'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Top := new TwBorder(self, 'w:top'); Left := new TwBorder(self, 'w:left'); Bottom := new TwBorder(self, 'w:bottom'); @@ -8640,13 +8640,13 @@ type TwTblBorders=class(NodeInfo) tl2br.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Top','name':Top.NodeName,'obj':Top,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') ,('field':'Left','name':Left.NodeName,'obj':Left,'attrEx':'','nodeType':'','attrName':'', 'desc':'左边框属性', 'class':'TwBorder') ,('field':'Bottom','name':Bottom.NodeName,'obj':Bottom,'attrEx':'','nodeType':'','attrName':'', 'desc':'底边框属性', 'class':'TwBorder') @@ -8674,20 +8674,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTblpPr /////////////////////////////////////////////////////////////// -type TwTblpPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblpPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTblpPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblpPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8696,13 +8696,13 @@ type TwTblpPr=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("bottomFromText", "w:bottomFromText ", bottomFromText, "指定当前浮动表与该浮动表下方段落中文本顶部之间应保持的最小距离。"),("horizAnchor", "w:horizAnchor", horizAnchor, "指定水平定位的基础对象。"),("leftFromText", "w:leftFromText", leftFromText, "指定当前浮动表与该浮动表左侧段落中文本边缘之间应保持的最小距离。"),("rightFromText", "w:rightFromText", rightFromText, "指定当前浮动表与该浮动表右侧段落中文本边缘之间应保持的最小距离。"),("tblpX", "w:tblpX", tblpX, "指定浮动表的绝对水平位置。此绝对位置是相对于horzAnchor属性为此浮动表指定的水平定位点指定的。"),("tblpXSpec", "w:tblpXSpec", tblpXSpec, "指定浮动表的相对水平位置。此相对位置是相对于此浮动表的horizAnchor属性指定的水平定位点指定的。"),("tblpY", "w:tblpY", tblpY, "指定浮动表的绝对垂直位置。此绝对位置是相对于此浮动表的vertAnchor属性指定的垂直锚点指定的。"),("tblpYSpec", "w:tblpYSpec", tblpYSpec, "指定浮动表的相对垂直位置。此相对位置是相对于此浮动表的vertAnchor属性指定的垂直锚点指定的。"),("topFromText", "w:topFromText", topFromText, "指定当前浮动表与该浮动表上方段落中文本底部边缘之间应保持的最小距离。"),("vertAnchor", "w:vertAnchor", vertAnchor, "指定应根据其计算tblpY属性中的垂直定位的基础对象。")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8724,20 +8724,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTblPr /////////////////////////////////////////////////////////////// -type TwTblPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTblPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Shading := new TwShading(self, 'w:shd'); Borders := new TwTblBorders(self, 'w:tblBorders'); CellMar := new TTblCellMar(self, 'w:tblCellMar'); @@ -8754,13 +8754,13 @@ type TwTblPr=class(NodeInfo) tblpPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'StyleID','name':'w:tblStyle','obj':StyleID,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'样式ID', 'class':'') ,('field':'Width','name':'w:tblW','obj':Width,'attrEx':'w:w','nodeType':'','attrName':'', 'desc':'表格宽度', 'class':'') ,('field':'WidthType','name':'w:tblW','obj':WidthType,'attrEx':'w:type','nodeType':'','attrName':'', 'desc':'宽度属性的单位。如"auto"表示根据内容调整,此时需要设置"width=0"; "pct"是按比例设置,转换比例是50, 10%时候需要width为500; "dxa"表示自定义宽度,此时width单位是twips,即1cm=567twips', 'class':'') @@ -8812,20 +8812,20 @@ End; /////////////////////////////////////////////////////////////// /// TwGridCol /////////////////////////////////////////////////////////////// -type TwGridCol=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:gridCol'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwGridCol=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:gridCol'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8834,13 +8834,13 @@ type TwGridCol=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("W", "w:w", W, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8853,20 +8853,20 @@ End; /////////////////////////////////////////////////////////////// /// TwTblGrid /////////////////////////////////////////////////////////////// -type TwTblGrid=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblGrid'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TwTblGrid=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblGrid'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin GridCol := array(); //TODO... End; @@ -8876,13 +8876,13 @@ type TwTblGrid=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'GridCol','name':'w:gridCol','obj':GridCol,'attrEx':'','nodeType':'','attrName':'','arrObj':'array', 'desc':'', 'class':'TwGridCol') ) union ExtNodes; End; @@ -8896,20 +8896,20 @@ End; /////////////////////////////////////////////////////////////// /// TTableImpl /////////////////////////////////////////////////////////////// -type TTableImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tbl'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTableImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tbl'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin TblPr := new TwTblPr(self, 'w:tblPr'); TblGrid := new TwTblGrid(self, 'w:tblGrid'); TR := array(); @@ -8923,13 +8923,13 @@ type TTableImpl=class(NodeInfo) TblGrid.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'TblPr','name':TblPr.NodeName,'obj':TblPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwTblPr') ,('field':'TblGrid','name':TblGrid.NodeName,'obj':TblGrid,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwTblGrid') ,('field':'TR','name':'w:tr','obj':TR,'attrEx':'','nodeType':'','attrName':'','arrObj':'array', 'desc':'', 'class':'TwTr') @@ -8947,20 +8947,20 @@ End; /////////////////////////////////////////////////////////////// /// TCorePropertiesImpl /////////////////////////////////////////////////////////////// -type TCorePropertiesImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:p'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TCorePropertiesImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:p'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -8969,13 +8969,13 @@ type TCorePropertiesImpl=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -8987,20 +8987,20 @@ End; /////////////////////////////////////////////////////////////// /// TPictureImpl /////////////////////////////////////////////////////////////// -type TPictureImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:p'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TPictureImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:p'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin pPr := new TwpPr(self, 'w:pPr'); Run := new TRunImpl(self, 'w:r'); //TODO... @@ -9013,13 +9013,13 @@ type TPictureImpl=class(NodeInfo) Run.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'pPr','name':pPr.NodeName,'obj':pPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TwpPr') ,('field':'Run','name':Run.NodeName,'obj':Run,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TRunImpl') ) union ExtNodes; @@ -9035,20 +9035,20 @@ End; /////////////////////////////////////////////////////////////// /// TpBdr /////////////////////////////////////////////////////////////// -type TpBdr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:pBdr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TpBdr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:pBdr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin top := new TwBorder(self, 'w:top'); left := new TwBorder(self, 'w:left'); bottom := new TwBorder(self, 'w:bottom'); @@ -9067,13 +9067,13 @@ type TpBdr=class(NodeInfo) Between.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'top','name':top.NodeName,'obj':top,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') ,('field':'left','name':left.NodeName,'obj':left,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') ,('field':'bottom','name':bottom.NodeName,'obj':bottom,'attrEx':'','nodeType':'','attrName':'', 'desc':'边框属性', 'class':'TwBorder') @@ -9095,20 +9095,20 @@ End; /////////////////////////////////////////////////////////////// /// TLatentStyle /////////////////////////////////////////////////////////////// -type TLatentStyle=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:lsdException'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TLatentStyle=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:lsdException'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9117,13 +9117,13 @@ type TLatentStyle=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Name", "w:name", Name, ""),("Count", "w:count", Count, ""),("defLockedState", "w:defLockedState", defLockedState, ""),("defQFormat", "w:defQFormat", defQFormat, ""),("defSemiHidden", "w:defSemiHidden", defSemiHidden, ""),("defUIPriority", "w:defUIPriority", defUIPriority, ""),("defUnhideWhenUsed", "w:defUnhideWhenUsed", defUnhideWhenUsed, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -9142,20 +9142,20 @@ End; /////////////////////////////////////////////////////////////// /// TtblStylePr /////////////////////////////////////////////////////////////// -type TtblStylePr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tblStylePr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TtblStylePr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tblStylePr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin pPr := new TwpPr(self, 'w:pPr'); rPr := new TwrPr(self, 'w:rPr'); TrPr := new TwTrPr(self, 'w:trPr'); @@ -9174,13 +9174,13 @@ type TtblStylePr=class(NodeInfo) TcPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'pPr','name':pPr.NodeName,'obj':pPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'段落格式', 'class':'TwpPr') ,('field':'rPr','name':rPr.NodeName,'obj':rPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'字体属性', 'class':'TwrPr') ,('field':'TrPr','name':TrPr.NodeName,'obj':TrPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'表格行属性', 'class':'TwTrPr') @@ -9202,20 +9202,20 @@ End; /////////////////////////////////////////////////////////////// /// TDocxStyleImpl /////////////////////////////////////////////////////////////// -type TDocxStyleImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:style'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TDocxStyleImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:style'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin TblStyle := new TtblStylePr(self, 'w:tblStylePr'); pPr := new TwpPr(self, 'w:pPr'); rPr := new TwrPr(self, 'w:rPr'); @@ -9236,13 +9236,13 @@ type TDocxStyleImpl=class(NodeInfo) TcPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("StyleID", "w:styleId", StyleID, "样式ID(数字或字符串)。"),("Default", "w:default", Default, "是否缺省样式,如缺省段落、缺省表格样式"),("wType", "w:type", wType, "样式类型(paragraph、chartacter、table)"),("CustomStyle ", "w:customStyle ", CustomStyle , "disable")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Name','name':'w:name','obj':Name,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'样式名称', 'class':'') ,('field':'Aliases','name':'w:aliases','obj':Aliases,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'样式别名.', 'class':'') ,('field':'AutoRedefine','name':'w:autoRedefine','obj':AutoRedefine,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'文本变动时,是否自动修改样式.', 'class':'') @@ -9302,20 +9302,20 @@ End; /////////////////////////////////////////////////////////////// /// TDocPartObj /////////////////////////////////////////////////////////////// -type TDocPartObj=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:docPartObj'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TDocPartObj=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:docPartObj'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9324,13 +9324,13 @@ type TDocPartObj=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'docPartGallery','name':'w:docPartGallery','obj':docPartGallery,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'docPartUnique','name':'w:docPartUnique','obj':docPartUnique,'attrEx':'','nodeType':'empty','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; @@ -9346,20 +9346,20 @@ End; /////////////////////////////////////////////////////////////// /// TSdtPr /////////////////////////////////////////////////////////////// -type TSdtPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:sdtPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSdtPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:sdtPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin rPr := new TwrPr(self, 'w:rPr'); docPartObj := new TDocPartObj(self, 'w:docPartObj'); //TODO... @@ -9372,13 +9372,13 @@ type TSdtPr=class(NodeInfo) docPartObj.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'rPr','name':rPr.NodeName,'obj':rPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'字体属性', 'class':'TwrPr') ,('field':'ID','name':'w:id','obj':ID,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'', 'class':'') ,('field':'docPartObj','name':docPartObj.NodeName,'obj':docPartObj,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TDocPartObj') @@ -9396,20 +9396,20 @@ End; /////////////////////////////////////////////////////////////// /// TSdtEndPr /////////////////////////////////////////////////////////////// -type TSdtEndPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:sdtEndPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSdtEndPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:sdtEndPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin rPr := new TwrPr(self, 'w:rPr'); //TODO... End; @@ -9420,13 +9420,13 @@ type TSdtEndPr=class(NodeInfo) rPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'rPr','name':rPr.NodeName,'obj':rPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'字体属性', 'class':'TwrPr') ) union ExtNodes; End; @@ -9440,20 +9440,20 @@ End; /////////////////////////////////////////////////////////////// /// TSdtContent /////////////////////////////////////////////////////////////// -type TSdtContent=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:sdtContent'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TSdtContent=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:sdtContent'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9462,13 +9462,13 @@ type TSdtContent=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -9480,20 +9480,20 @@ End; /////////////////////////////////////////////////////////////// /// TTableContentImpl /////////////////////////////////////////////////////////////// -type TTableContentImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:sdt'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTableContentImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:sdt'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin sdtPr := new TSdtPr(self, 'w:sdtPr'); sdtEndPr := new TSdtEndPr(self, 'w:sdtEndPr'); sdtContent := new TSdtContent(self, 'w:sdtContent'); @@ -9508,13 +9508,13 @@ type TTableContentImpl=class(NodeInfo) sdtContent.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'sdtPr','name':sdtPr.NodeName,'obj':sdtPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSdtPr') ,('field':'sdtEndPr','name':sdtEndPr.NodeName,'obj':sdtEndPr,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSdtEndPr') ,('field':'sdtContent','name':sdtContent.NodeName,'obj':sdtContent,'attrEx':'','nodeType':'','attrName':'', 'desc':'', 'class':'TSdtContent') @@ -9532,20 +9532,20 @@ End; /////////////////////////////////////////////////////////////// /// TTabStopsImpl /////////////////////////////////////////////////////////////// -type TTabStopsImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tabs'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTabStopsImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tabs'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Tabs := array(); //TODO... End; @@ -9555,13 +9555,13 @@ type TTabStopsImpl=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'Tabs','name':'w:tab','obj':Tabs,'attrEx':'','nodeType':'','attrName':'','arrObj':'array', 'desc':'', 'class':'TTabStop') ) union ExtNodes; End; @@ -9575,20 +9575,20 @@ End; /////////////////////////////////////////////////////////////// /// TTabStop /////////////////////////////////////////////////////////////// -type TTabStop=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:tab'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTabStop=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:tab'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9597,13 +9597,13 @@ type TTabStop=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Val", "w:val", Val, "Specifies the type of custom tab stop, which determines the behavior of the tab stop and the alignment which shall be applied to text entered at the current custom tab stop."),("leader", "w:leader", leader, "Specifies the character which shall be used to fill in the space created by a tab which ends at this custom tab stop. This character shall be repeated as required to completely fill the tab spacing generated by the tab character."),("Position", "w:pos", Position, "Specifies the position of the current custom tab stop with respect to the current page margins. ")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -9618,20 +9618,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumber /////////////////////////////////////////////////////////////// -type TNumber=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:num'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumber=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:num'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9640,13 +9640,13 @@ type TNumber=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("numId", "w:numId", numId, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'abstractNumId','name':'w:abstractNumId','obj':abstractNumId,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -9661,20 +9661,20 @@ End; /////////////////////////////////////////////////////////////// /// TLevel /////////////////////////////////////////////////////////////// -type TLevel=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:lvl'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TLevel=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:lvl'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin pPr := new TwpPr(self, 'w:pPr'); rPr := new TwrPr(self, 'w:rPr'); //TODO... @@ -9687,13 +9687,13 @@ type TLevel=class(NodeInfo) rPr.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("ilvl", "w:ilvl", ilvl, "内容是否包含小数。"),("tentative", "w:tentative", tentative, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'start','name':'w:start','obj':start,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'给定编号级别定义中父编号级别使用的编号的起始值。', 'class':'') ,('field':'numFmt','name':'w:numFmt','obj':numFmt,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'编号类型(单极、多级、项目编号等)。', 'class':'') ,('field':'lvlText','name':'w:lvlText','obj':lvlText,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'编号文本内容格式,如(%1.%2.%3.%4)。', 'class':'') @@ -9719,20 +9719,20 @@ End; /////////////////////////////////////////////////////////////// /// TNumStyleImpl /////////////////////////////////////////////////////////////// -type TNumStyleImpl=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'w:abstractNum'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TNumStyleImpl=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'w:abstractNum'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin lvl := new TLevel(self, 'w:lvl'); //TODO... End; @@ -9743,13 +9743,13 @@ type TNumStyleImpl=class(NodeInfo) lvl.InitRootNode(node); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("abstractNumId", "w:abstractNumId", abstractNumId, "latentStyles编号ID(编号段落的外观和行为)")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'nsid','name':'w:nsid','obj':nsid,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'disable', 'class':'') ,('field':'multiLevelType','name':'w:multiLevelType','obj':multiLevelType,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'编号类型', 'class':'') ,('field':'tmpl','name':'w:tmpl','obj':tmpl,'attrEx':'w:val','nodeType':'','attrName':'', 'desc':'该元素指定了一个唯一的十六进制代码,该代码可用于确定应用程序用户界面中显示该抽象编号定义的位置。', 'class':'') @@ -9770,20 +9770,20 @@ End; /////////////////////////////////////////////////////////////// /// TExcelTable /////////////////////////////////////////////////////////////// -type TExcelTable=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'table'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TExcelTable=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'table'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9792,13 +9792,13 @@ type TExcelTable=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Xmlns", "xmlns", Xmlns, ""),("Mc", "xmlns:mc", Mc, ""),("Ignorable", "mc:Ignorable", Ignorable, ""),("Xr", "xmlns:xr", Xr, ""),("Xr3", "xmlns:xr3", Xr3, ""),("Id", "id", Id, ""),("Name", "name", Name, ""),("DisplayName", "displayName", DisplayName, ""),("Ref", "ref", Ref, ""),("HeaderRowCount", "HeaderRowCount", HeaderRowCount, ""),("TotalsRowShown", "totalsRowShown", TotalsRowShown, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return array(('field':'AutoFilter','name':'autoFilter','obj':AutoFilter,'attrEx':'ref','nodeType':'','attrName':'', 'desc':'', 'class':'') ) union ExtNodes; End; @@ -9823,20 +9823,20 @@ End; /////////////////////////////////////////////////////////////// /// TTableStyle /////////////////////////////////////////////////////////////// -type TTableStyle=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'tableStyleInfo'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TTableStyle=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'tableStyleInfo'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9845,20 +9845,20 @@ type TTableStyle=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Name", "tableName", Name, ""),("TableStyle", "name", TableStyle, ""),("ShowFirstColumn", "showFirstColumn", ShowFirstColumn, ""),("ShowLastColumn", "showLastColumn", ShowLastColumn, ""),("ShowRowStripes", "showRowStripes", ShowRowStripes, ""),("ShowColumnStripes", "showColumnStripes", ShowColumnStripes, ""),("HeaderRowCount", "HeaderRowCount", HeaderRowCount, ""),("TotalsRowShown", "totalsRowShown", TotalsRowShown, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; - Property TableName read Name write writeName; - Function writeName(n); - Begin - Name := class(TSXml).CurCodePageToUtf8(n); + Property TableName read Name write writeName; + Function writeName(n); + Begin + Name := class(TSXml).CurCodePageToUtf8(n); End; //Attributes @@ -9877,20 +9877,20 @@ End; /////////////////////////////////////////////////////////////// /// TBreak /////////////////////////////////////////////////////////////// -type TBreak=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'brk'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TBreak=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'brk'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin Max := 16383; Man := 1; //TODO... @@ -9901,13 +9901,13 @@ type TBreak=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Id", "id", Id, ""),("Max", "max", Max, ""),("Man", "man", Man, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -9922,20 +9922,20 @@ End; /////////////////////////////////////////////////////////////// /// TProtect /////////////////////////////////////////////////////////////// -type TProtect=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'sheetProtection'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TProtect=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'sheetProtection'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -9944,13 +9944,13 @@ type TProtect=class(NodeInfo) RootObj := node; End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("Password", "password", Password, ""),("AlgorithmName", "algorithmName", AlgorithmName, ""),("HashValue", "hashValue", HashValue, ""),("SaltValue", "saltValue", SaltValue, ""),("SpinCount", "spinCount", SpinCount, ""),("Sheet", "sheet", Sheet, ""),("EditObjects", "objects", EditObjects, ""),("EditScenarios", "scenarios", EditScenarios, ""),("FormatCells", "formatCells", FormatCells, ""),("FormatColumns", "formatColumns", FormatColumns, ""),("FormatRows", "formatRows", FormatRows, ""),("InsertColumns", "insertColumns", InsertColumns, ""),("InsertRows", "insertRows", InsertRows, ""),("InsertHyperlinks", "insertHyperlinks", InsertHyperlinks, ""),("DeleteColumns", "deleteColumns", DeleteColumns, ""),("DeleteRows", "deleteRows", DeleteRows, ""),("SelectLockedCells", "selectLockedCells", SelectLockedCells, ""),("Sort", "sort", Sort, ""),("AutoFilter", "autoFilter", AutoFilter, ""),("PivotTables", "pivotTables", PivotTables, ""),("SelectUnLockedCells", "selectUnlockedCells", SelectUnLockedCells, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -9983,20 +9983,20 @@ End; /////////////////////////////////////////////////////////////// /// TCalcPr /////////////////////////////////////////////////////////////// -type TCalcPr=class(NodeInfo) - Function Create(); overload; - Begin - Create(nil, 'calcPr'); - End; - - Function Create(p, name); overload; - Begin - Class(NodeInfo).Create(p, name); - Init(); - End; - - Function Init(); - Begin +type TCalcPr=class(NodeInfo) + Function Create(); overload; + Begin + Create(nil, 'calcPr'); + End; + + Function Create(p, name); overload; + Begin + Class(NodeInfo).Create(p, name); + Init(); + End; + + Function Init(); + Begin //TODO... End; @@ -10135,13 +10135,13 @@ type TCalcPr=class(NodeInfo) XMLConCurrentManualCount := class(TSXml).CurCodePageToUtf8(str); End; - Function GetAttrs(); override; - Begin + Function GetAttrs(); override; + Begin return array(("CalCId", "calcId", XMLCalCId, ""),("CalcMode", "calcMode", XMLCalcMode, ""),("RefMode", "refMode", XMLRefMode, ""),("Iterate", "iterate", XMLIterate, ""),("IterateCount", "iterateCount", XMLIterateCount, ""),("IterateDelta", "iterateDelta", XMLIterateDelta, ""),("CalcOnSave", "calcOnSave", XMLCalcOnSave, ""),("FullPrecision", "fullPrecision", XMLFullPrecision, ""),("ConCurrentCalc", "conCurrentCalc", XMLConCurrentCalc, ""),("ConCurrentManualCount", "conCurrentManualCount", XMLConCurrentManualCount, "")) union ExtAttr; End; - Function GetChildren(); override; - Begin + Function GetChildren(); override; + Begin return ExtNodes; End; @@ -10160,5403 +10160,5405 @@ type TCalcPr=class(NodeInfo) //Nodes End; -/////////////////////////////////////////////////////////////////////////////////////////// -///DOCX文档实现 - -Type TRange = Class - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(t);overload; - Begin - //array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r)) - Init(t); - End; - - Function Init(t); - Begin - RunArr_ := t; - End; - - ///清除全部选中内容 - Function Clear(); - Begin - _clear(0);//清除全部w:r - End; - - Property Font read readFont; - Function readFont(); - Begin - if ifNil(rPr_) then - rPr_ := new TwrPr(); - return rPr_; - End; - - Property Text read readText write writeText; - Function readText(); - Begin - return _text(RunArr_); - End; - - Function writeText(txt); - Begin - r := RunArr_[0:0,:]; - _clear(1);//只保留第1段 - run := new TRun(r[0]['rNode']); - run.SetText(txt); - return r; - End; - - ///应用字体样式 - Function Apply(); - Begin - if not ifObj(rPr_) then return; - arr := rPr_.Marshal(); - if length(arr['attributes']) or length(arr['children']) then Begin - for i:=0 to length(RunArr_)-1 do Begin - rPr := class(TSXml).GetNode(RunArr_[i]['rNode'], 'w:rPr', 'first'); - class(TSXml).UpdateNode(rPr, arr['attributes'], arr['children']); - End; - End; - End; - - Function _clear(first); - Begin - for i:=first to length(RunArr_)-1 do Begin - pNode := RunArr_[i]['pNode']; - pNode.DeleteChild(RunArr_[i]['rNode']); - rNode := pNode.FirstChildElement('w:r'); - if not ifObj(rNode) then - pNode.Parent().DeleteChild(pNode); - End; - End; - - rPr_;//字体格式 - RunArr_; -End; - -Type DocObject = Class - Function Create(); - Begin - pageNo_ := 0; - linePos_ := 0.; - End; - - Function Name(); - Begin - return name_; - End; - - ///修改属性,包括样式、边框、底纹、字体等 - Function Apply();virtual; - Begin - End; - - ///前一个对象 - Function Prev();virtual; - Begin - return _next_prev_Impl(node_.PrevElement(name_)); - End; - - ///下一个对象 - Function Next();virtual; - Begin - return _next_prev_Impl(node_.NextElement(name_)); - End; - - ///添加批注 - ///obj:TDocComment对象 - ///返回:成功 true - Function AddComment(obj); - Begin - id := obj.ID; - r := _split_range(obj.sPos, obj.SelectLength); - cnt := length(r); - if cnt then Begin - rNode := r[0]['rNode']; - beg := rNode.Parent().InsertBeforeChild(rNode, 'element', 'w:commentRangeStart'); - beg.SetAttribute('w:id', id); - - rNode := r[cnt-1]['rNode']; - eNode := rNode.Parent().InsertAfterChild(rNode, 'element', 'w:commentRangeEnd'); - eNode.SetAttribute('w:id', id); - - r := rNode.Parent().InsertAfterChild(eNode, 'element', 'w:r'); - cr := r.InsertFirstChild('element', 'w:commentReference'); - cr.SetAttribute('w:id', id); - return true; - End; - return false; - End; - - ///修订插入 - ///obj:TRevision对象 - ///返回:成功 true - Function AddRevision(obj); - Begin - obj.NodeName := 'w:ins'; - obj.name_ := obj.NodeName; - r := _split_range(obj.sPos, 0); - if length(r) then Begin - rNode := r[length(r)-1]['rNode']; - node := rNode.Parent().InsertAfterChild(rNode, obj.Marshal()); - End - else Begin - pPr := node_.FirstChildElement('w:pPr'); - if ifObj(pPr) then - node := node_.InsertAfterChild(pPr, obj.Marshal()); - else - node := node_.InsertFirstChild(obj.Marshal()); - rNode := node.NextElement('w:r'); - End; - if ifObj(rNode) then Begin - data := rNode.Marshal(); - node2 := node.InsertFirstChild(data[0]); - End - else Begin - node2 := node.InsertEndChild('element', 'w:r'); - End; - run := new TRun(node2); - run.SetText(obj.InsText_, true); - obj.Init(node); - return true; - End; - - ///修订删除 - ///obj:TRevision对象 - ///返回:成功 true,失败 false - Function DelRevision(obj); - Begin - r := _split_range(obj.sPos, obj.SelectLength); - for i:=0 to length(r)-1 do Begin - rNode := r[i]['rNode']; - delNode := rNode.Parent().InsertAfterChild(rNode, obj.Marshal()); - rXml := string(rNode.Data()); - rXml := ReplaceStr(rXml, '', ''); - delNode.InsertFirstChild(rXml); - rNode.Parent().DeleteChild(rNode); - End; - return length(r); - End; - - Function _next_prev_Impl(n); - Begin - if ifObj(n) then Begin - case name_ of - 'w:p': - p := new TParagraph(p); - 'w:tbl': - p := new TTable(n); - 'w:r': - p := new TRun(n); - 'w:del','w:ins': - p := new TRevision(n); - End; - if ifObj(p) then Begin - p.name_ := name; - p.node_ := n; - End; - End; - return p; - End; - - ///文本内容 - Function Text();virtual; - Begin - r := TextArray(); - return _text(r); - End; - - //所有文字信息(包括位置信息) - //返回:table(包括w:r节点) - Function TextArray();virtual; - Begin - r := array(); - node := node_.FirstChildElement('w:r'); - while ifObj(node) do Begin - r[ind]['pNode'] := node_; - r[ind]['pIndex'] := -1; - r[ind]['rNode'] := node; - r[ind]['rIndex'] := ind; - ind++; - node := node.NextElement('w:r'); - End; - return r; - End; - - ///段落中插入文字 - Function AddText(sPos, txt); - Begin - if sPos < 0 then Begin //段落后追加 - lastNode := node_.LastChild('w:r'); - if ifObj(lastNode) then Begin - rNode := _duplicate_r(lastNode); - End - else Begin - rNode := node_.InsertEndChild('element','w:r'); - p := new TParagraph(node_); - p.CopyRunFormat(false, rNode); - End; - run := new TRun(rNode); - run.SetText(txt); - t := array(('pNode':node_, 'pIndex':-1, 'rNode':rNode, 'rIndex':-1)); - return new TRange(t); - End; - obj := new TRevision(); - obj.sPos := sPos; - obj.InsText := txt; - AddRevision(obj);//插入文字 - t := obj.Accept(); - return new TRange(t); - End; - - ///返回:TRange对象,(TBody、TParagraph、TCell)全部内容 - Function Range();overload; - Begin - t := TextArray(); - if not istable(t) then - return nil; - return new TRange(t); - End; - - ///sPos:起始位置 - ///rangeLength:内容长度 - ///返回:TRange对象,此函数非只读,执行此函数会重新调整段落中TRun结构 - Function Range(sPos, rangeLength);overload; - Begin - t := _split_range(sPos, rangeLength); - if not istable(t) then - return nil; - return new TRange(t); - End; - - ///返回文档中的位置 - Function Node(); - Begin - return node_; - End; - - Function _split_range(sPos, rangeLength); - Begin - t := array(); - if not ifInt(sPos) or not ifInt(rangeLength) or sPos < 0 then - return t; - r := TextArray(); - rSize := 0; - for i:=0 to length(r)-1 do Begin - run := new TRun(r[i]['rNode']); - txt := run.Text(); - if class(TSXml).IsUtf8() then - txt := UTF8ToAnsi(txt); - txtLen := lengthW(txt); - if rangeLength >= 0 and sPos + rangeLength <= rSize then Begin - return t; - End; - if rangeLength = 0 then Begin //w:ins情况 - if sPos >= txtLen + rSize then Begin //前 - rSize += txtLen; - t[0] := r[i]; - End - else Begin //一分为二,取头部 - if sPos = rSize then - return t;//正好文档开头 - t[0] := r[i]; - r2 := _duplicate_r(r[i]['rNode']); - _adjust_r(r[i]['rNode'], 0, sPos - rSize); - _adjust_r(r2, sPos - rSize, txtLen); - return t; - End; - End - else Begin //w:del情况 - if rangeLength < 0 or (sPos <= rSize and sPos + rangeLength >= rSize + txtLen) then Begin //包含全部w:r - t[ length(t) ] := r[i]; - rSize += txtLen; - End - else if sPos >= txtLen + rSize then Begin //前 - rSize += txtLen; - End - else if sPos >= rSize and sPos < rSize + txtLen and sPos + rangeLength >= rSize + txtLen then Begin //一分为二,取尾部 - if sPos = rSize then Begin //正好整个run - t[ length(t) ] := r[i]; - End - else Begin //一分为二,取尾部 - r2 := _duplicate_r(r[i]['rNode']); - _adjust_r(r[i]['rNode'], 0, sPos - rSize); - _adjust_r(r2, sPos - rSize, txtLen); - tmp := r[i]; - tmp['rNode'] := r2; - tmp['rIndex'] := r[i]['rIndex'] + 1; - t[ length(t) ] := tmp; - End; - rSize += txtLen; - End - else if sPos + rangeLength <= rSize + txtLen then Begin - if sPos + rangeLength = rSize + txtLen then Begin //正好整个run - t[ length(t) ] := r[i]; - End - else if sPos <= rSize then Begin //一分为二,取头部 - t[ length(t) ] := r[i]; - r2 := _duplicate_r(r[i]['rNode']); - _adjust_r(r[i]['rNode'], 0, rangeLength - (rSize - sPos)); - _adjust_r(r2, rangeLength - (rSize - sPos), txtLen); - End - else Begin //一分为三,取中间 - r2 := _duplicate_r(r[i]['rNode']); - r3 := _duplicate_r(r2); - _adjust_r(r[i]['rNode'], 0, sPos - rSize); - _adjust_r(r2, sPos - rSize, rangeLength); - _adjust_r(r3, sPos - rSize + rangeLength, txtLen); - tmp := r[i]; - tmp['rNode'] := r2; - tmp['rIndex'] := r[i]['rIndex'] + 1; - t[0] := tmp; - End; - rSize += txtLen; - return t; - End - End; - End; - return t; - End; - - //复制w:r节点 - Function _duplicate_r(node); - Begin - data := node.Marshal(); - return node.Parent().InsertAfterChild(node, data[0]); - End; - - //调整w:r节点 - Function _adjust_r(node, sPos, rangeLength); - Begin - rSize := 0; - ePos := sPos + rangeLength; - delT := array(); - tNode := node.FirstChildElement('w:t'); - while ifObj(tNode) do Begin - txt := UTF8ToAnsi(tNode.GetText()); - txtLen := lengthW(txt); - if sPos >= rSize + txtLen then Begin //删除头部文字 - delT[cnt++] := tNode; - rSize += txtLen; - End - else if sPos >= rSize and sPos < rSize + txtLen and ePos <= rSize + txtLen then Begin //只取中间文字 - if sPos <> rSize or ePos <> rSize + txtLen then Begin //文字内容有变化 - mCnt := ePos - sPos; - if sPos = rSize then - nStr := leftstr(txt, mCnt); - else if ePos = rSize + txtLen then - nStr := rightstr(txt, mCnt); - else - nStr := midstr(txt, sPos - rSize + 1, mCnt); - tNode.SetValue(AnsiToUTF8(nStr)); - End; - rSize += txtLen; - End - else if sPos >= rSize and sPos < rSize + txtLen and ePos > rSize + txtLen then Begin //只取尾巴文字 - if sPos <> rSize then Begin //文字内容有变化 - mCnt := txtLen - (sPos - rSize); - nStr := rightstr(txt, mCnt); - tNode.SetValue(AnsiToUTF8(nStr)); - End; - End - else if sPos < rSize and ePos >= rSize + txtLen then Begin //取值范围 - rSize += txtLen; - End - else Begin //删除尾部文字 - delT[cnt++] := tNode; - End - rSize += txtLen; - tNode := tNode.NextElement('w:t'); - End; - - for i:=0 to length(delT)-1 do - node.DeleteChild(delT[i]); - End; - - node_; - name_:string; - pageNo_; //页码 - linePos_; //行位置 -End; - -Type TRevision = Class(DocObject, TRevisionImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Init(node); - End; - - Function Init(node); - Begin - node_ := node; - name_ := 'w:del'; - if ifObj(node_) then Begin - name_ := node_.GetName(); - paragraph_ := new TParagraph(node_); - End; - Date := class(TSXml).GetDatetimeStr(now()); - Class(TRevisionImpl).Create(nil, name_); - InitRootNode(node); - End; - - Property InsText read readInsText write writeInsText; - Function readInsText(); - Begin - return class(TSXml).Utf8ToCurCodePage(InsText_); - End; - - Function writeInsText(txt); - Begin - InsText_ := class(TSXml).CurCodePageToUtf8(txt); - End; - - ///修订类型 - ///返回:string, 删除:'del'、添加:'ins' - Function Act(); - Begin - return name_ = 'w:del' ? 'del' : 'ins'; - End; - - ///文字内容 - Function Text();override; - Begin - return paragraph_.Text(); - End; - - ///接受修订 - Function Accept(); - Begin - if name_ = 'w:del' then Begin - node_.Parent().DeleteChild(node_); - return nil; - End; - r := array(); - //w:ins - runs := paragraph_.GetRuns(); - node := node_; - for i:=0 to length(runs)-1 do Begin - rData := runs[i].node_.Marshal(); - node := node.Parent().InsertAfterChild(node, rData[0]);//接受修订,复制... - r[length(r)] := array('pNode':node.Parent(), 'pIndex':-1, 'rNode':node, 'rInde':-1); - End; - node_.Parent().DeleteChild(node_); - return r; - End; - - ///拒绝修订 - Function Reject(); - Begin - if name_ = 'w:ins' then Begin - node_.Parent().DeleteChild(node_); - return; - End; - //w:del - runs := paragraph_.GetRuns(); - node := node_; - for i:=0 to length(runs)-1 do Begin - rXml := string(runs[i].node_.Data()); - rXml := ReplaceStr(rXml, '', ''); - node := node.Parent().InsertAfterChild(node, rXml);//接受修订,复制... - End; - node_.Parent().DeleteChild(node_); - End; - - paragraph_; - CommentID:integer; - sPos:integer; - SelectLength:integer; - InsText_:string; -End; - -Type TDocComment = Class(TDocCommentImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - node_ := node; - name_ := 'w:comment'; - Date := class(TSXml).GetDatetimeStr(now()); - Class(TDocCommentImpl).Create(nil, name_); - InitRootNode(node); - End; - - ///批注文字内容 - Function Text(); - Begin - txt := ''; - rCnt := 0; - for i:= 0 to length(commentsArray_)-1 do Begin - if commentsArray_[i]['Name'] := 'w:r' then Begin - if rCnt and commentsArray_[i]['pIndex'] <> commentsArray_[i-1]['pIndex'] then - txt += '\n'; - run := new TRun(commentsArray_[i]['rNode']); - txt += run.Text(); - rCnt ++; - End; - End; - return txt; - End; - - ///删除批注 - Function Delete(); - Begin - commentsArray_[0]['pNode'].DeleteChild( commentsArray_[0]['rNode'] ); - cnt := length(commentsArray_) - 1; - r := commentsArray_[cnt]['rNode'].Next('w:r'); - if ifObj(r) then Begin - commentReference := r.FirstChildElement('w:commentReference'); - if ifObj(commentReference) then Begin - r.DeleteChild( commentReference ); - End; - End; - commentsArray_[cnt]['pNode'].DeleteChild( commentsArray_[cnt]['rNode'] ); - if not ifObj(r.FirstChildElement()) then Begin - r.Parent().DeleteChild( r ); - End; - End; - - CommentID:integer; - sPos:integer; - SelectLength:integer; - commentsArray_; -End; - -Type TDocComments = Class - Function Create(t); - Begin - commentsArray_ := t; - hash_ := sselect distinct ['ID'] from commentsArray_ where ['ID'] >= 0 end; - End; - - ///文档中全部的批注信息个数 - Function Count(); - Begin - return length(hash_); - End; - - ///文档中指定批注信息 - ///index:第index个批注信息 - ///返回:TDocComment对象 - Function Comment(index);overload; - Begin - if index < 0 or index >= length(hash_) then - return nil; - id := hash_[index]; - r := select thisrowindex as 'Index' from commentsArray_ where ['ID'] = id end; - if not istable(r) or length(r) <> 2 then - return nil; - t := select * from commentsArray_ where thisrowindex <= r[1]['Index'] and thisrowindex >= r[0]['Index'] end; - o := new TDocComment(); - o.commentsArray_ := t; - o.CommentID := t[0]['ID']; - return o; - End; - - hash_; - commentsArray_; -End; - -//w:pPr -// 'w:pStyle', 'w:keepNext', 'w:keepLines', 'w:pageBreakBefore', -// 'w:framePr', 'w:widowControl', 'w:numPr', 'w:suppressLineNumbers', -// 'w:pBdr', 'w:shd', 'w:tabs', 'w:suppressAutoHyphens', 'w:kinsoku', -// 'w:wordWrap', 'w:overflowPunct', 'w:topLinePunct', 'w:autoSpaceDE', -// 'w:autoSpaceDN', 'w:bidi', 'w:adjustRightInd', 'w:snapToGrid', -// 'w:spacing', 'w:ind', 'w:contextualSpacing', 'w:mirrorIndents', -// 'w:suppressOverlap', 'w:jc', 'w:textDirection', 'w:textAlignment', -// 'w:textboxTightWrap', 'w:outlineLvl', 'w:divId', 'w:cnfStyle', -// 'w:rPr', 'w:sectPr', 'w:pPrChange' - -//w:p -Type TWHyperLink = Class(TWHyperLinkImpl) - Function AddRun(txt, newLine); - Begin - o := new TRun(); - //o.Parent := self; - NewChildNode( array("field":"", "name":"w:r", "obj":o, "attrEx":"", "nodeType":"") ); - if txt then - o.SetText(txt); - if newLine then - o.Br.Type := ''; - return o; - End; -End; - -Type TParagraph = Class(DocObject, TParagraphImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Init(node); - End; - - Function Init(node); - Begin - node_ := node; - name_ := 'w:p'; - Class(TParagraphImpl).Create(nil, 'w:p'); - InitRootNode(node); - End; - - Function Root(); override; - Begin - return node_; - End; - - Property Format read readFormat; - Function readFormat(); - Begin - return pPr; - End; - - Property Font read readFont; - Function readFont(); - Begin - return pPr.rPr; - End; - - ///修改段落 - Function Apply(); override; - Begin - arr := Marshal(); - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - CopyRunFormat(false, nil); - End; - - ///修改段落内容 - ///返回:TRun对象 - Function SetText(str); - Begin - t := GetRuns(); - for i:=1 to length(t)-1 do Begin - node_.DeleteChild(t[i].node_); - End; - if length(t) then - rNode := t[0].node_; - else - rNode := node_.InsertEndChild('element', 'w:r'); - run := new TRun(rNode); - run.SetText(str); - return rNode; - End; - - ///制表位TTabStops对象 - ///返回:TTabStops对象 - // - // - // - // - Function TabStops(); - Begin - node := class(TSXml).GetNode(node_, 'w:pPr/w:tabs'); - if not ifObj(node) then - return nil; - return new TTabStops(node); - End; - - Function setParagraphText(rNode, tNode, txt); - Begin - if not ifObj(tNode) then Begin - tNode := rNode.FirstChildElement('w:t'); - if not ifObj(tNode) then - tNode := rNode.InsertFirstChild('element', 'w:t', txt); - End - else - tNode.SetValue(txt); - End; - - ///所有TRun对象列表 - ///返回:TRun对象列表 - Function GetRuns(); - Begin - t := array();//TRun Array - node := node_.FirstChildElement('w:r'); - while ifObj(node) do Begin - n := node; - name := node.GetName(); - node := node.NextElement('w:r'); - if name = 'w:r' then Begin - run := new TRun(n); - End - else if name = 'w:ins' then Begin - r := n.FirstChildElement('w:r'); - if not ifObj(r) then continue; - run := new TRun(r); - End - else - continue; - t[ length(t) ] := run; - End; - return t; - End; - - ///TRun对象 - ///返回:TRun对象 - Function GetRun(i); - Begin - runs := GetRuns(); - if i < 0 or i >= length(runs) then - return nil; - return runs[i]; - End; - - ///段落中添加内容 - ///返回:TRun对象 - Function AddRun(txt, newLine); - Begin - o := new TRun(); - //o.Parent := self; - NewChildNode( array("field":"", "name":"w:r", "obj":o, "attrEx":"", "nodeType":"") ); - if txt then - o.SetText(txt); - if newLine then - o.Br.Type := ''; - return o; - End; - - ///段落添加 - ///返回:TWHyperLink - Function AddHyperLink(); - Begin - o := new TWHyperLink(); - NewChildNode( array("field":"", "name":"w:r", "obj":o, "attrEx":"", "nodeType":"") ); - return o; - End; - - ///在段落对象后面追加TRun对象 - ///返回TRun对象 - Function AppendRun();overload; - Begin - node := node_.InsertEndChild('element','w:r'); - node.InsertFirstChild('element', 'w:rPr'); - return new TRun(node); - End; - - ///在段落某个TRun对象之后添加TRun对象 - ///run:TRun对象 - ///返回TRun对象 - Function AppendRun(run);overload; - Begin - node := run.NodeUri <> '' ? class(TSXml).GetNode(run.Root(), run.NodeUri) : run.Root(); - node := node_.InsertAfterChild(run.Root(), 'element','w:r'); - node.InsertFirstChild('element', 'w:rPr'); - return new TRun(node); - End; - - ///在段落对象开头添加TRun对象 - ///返回TRun对象 - Function PrependRun();overload; - Begin - node := node_.FirstChildElement('w:r'); - node := node_.InsertBeforeChild(node, 'element', 'w:r'); - node.InsertFirstChild('element', 'w:rPr'); - return new TRun(node); - End; - - ///在段落某个TRun对象之前添加TRun对象 - ///run:TRun对象 - ///返回TRun对象 - Function PrependRun(run);overload; - Begin - node := node_.InsertBeforeChild(run.Root(), 'element', 'w:r'); - node.InsertFirstChild('element', 'w:rPr'); - return new TRun(node); - End; - - ///段落中全部的修改标记(修订删除、修订插入) - ///返回:TRevision对象列表,array(TRevision...); - Function Revisions();overload; - Begin - return getDocumentObjects(node_, array('w:del', 'w:ins')); - End; - - ///段落指定修改标记(修订删除、修订插入) - ///index:第index个修改标记 - ///返回:TRevision对象 - Function Revisions(index);overload; - Begin - return getDocumentObject(node_, array('w:del', 'w:ins'), index); - End; - - ///段落中所有文本框 - ///返回:TTextBox对象数组 - Function TextBoxs();overload; - Begin - r := array(); - runs := GetRuns(); - for i:=0 to length(runs)-1 do Begin - node := class(TSXml).GetNode(runs[i].node_, 'mc:AlternateContent/mc:Fallback/w:pict/v:shape/v:textbox/w:txbxContent'); - if ifObj(node) then Begin - nodeEx := class(TSXml).GetNode(runs[i].node_, 'mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent'); - box := new TTextBox(node); - box.Init(node_, nodeEx); - r[length(r)] := box; - End - else Begin - node := class(TSXml).GetNode(runs[i].node_, 'w:pict/v:shape/v:textbox/w:txbxContent'); - if ifObj(node) then Begin - box := new TTextBox(node); - box.Init(node_, nil); - r[length(r)] := box; - End; - End; - End; - return r; - End; - - ///段落中指定文本框 - ///index:第index个文本框 - ///返回:TTextBox对象 - Function TextBoxs(index);overload; - Begin - r := TextBoxs(); - if index >= 0 and index < length(r) then - return r[index]; - return nil; - End; - - ///清除段落格式、字体格式 - Function ClearFormat(); - Begin - pPr := node_.FirstChildElement('w:pPr'); - //清除段落格式 - if ifObj(pPr) then - node_.DeleteChild(pPr); - //清除字体格式 - runs := GetRuns(); - for i:=0 to length(runs)-1 do Begin - runs[i].ClearFormat(); - End; - End; - - ///添加BookMark - ///返回:BookMark的名称,string - Function AddBookMark(bookMarkID); - Begin - pPr := node_.FirstChildElement('w:pPr'); - if ifObj(pPr) then - markStart := node_.InsertAfterChild(pPr, 'element', 'w:bookmarkStart'); - else - markStart := node_.InsertFirstChild('element', 'w:bookmarkStart'); - name := '_Toc' $ bookMarkID; - markStart.SetAttribute('w:name', name); - markStart.SetAttribute('w:id', bookMarkID); - markEnd := node_.InsertEndChild('element', 'w:bookmarkEnd'); - markEnd.SetAttribute('w:id', bookMarkID); - return name; - End; - - ///判断是否为空段落 - ///返回: bool - Function Empty(); - Begin - if ifObj(node_) then - begin - if ifObj(node_.FirstChildElement("w:r")) then return false; - sub_node := node_.FirstChildElement(); - if not ifObj(sub_node) then return true; - // 兼容wps - sub_node2 := sub_node.NextElement(); - if sub_node.GetName() = 'w:bookmarkStart' and ifObj(sub_node2) and sub_node2.GetName() = 'w:bookmarkEnd' then - return true; - // 兼容word - if sub_node.GetName() = 'w:pPr' and not ifObj(sub_node2) then - return true; - end - return false; - End; - - ///获取当前段落的上一个段落 - ///返回:TParagraph对象 - Function PrevParagraph(); - Begin - if ifObj(node_) then - begin - node := node_.PrevElement('w:p'); - return ifObj(node) ? new TParagraph(node) : nil; - end - End; - - Function CopyRunFormat(del, toRunNode); - Begin - rPr := class(TSXml).GetNode(node_, 'w:pPr/w:rPr'); - dom := ifObj(rPr) ? rPr.Marshal() : array(); - if ifObj(toRunNode) then Begin - _copyRunFormat(toRunNode, dom, del); - return; - End; - - //复制到所有run - runs := GetRuns(); - for i:=0 to length(runs)-1 do - _copyRunFormat(runs[i].node_, dom, del); - End; - - //不能复用TRun::CopyFontFormat(),该函数是完全替换字体属性 - //本函数是追加、修改字体属性 - Function _copyRunFormat(toRunNode, dom, del); - Begin - tNode := toRunNode.FirstChildElement('w:t'); - rPr2 := toRunNode.FirstChildElement('w:rPr'); - if del and ifObj(rPr2) then - rPr2.node_.DeleteChildren(); - else if ifObj(tNode) and not ifObj(rPr2) then - rPr2 := class(TSXml).GetNode(toRunNode, 'w:rPr', 'first'); - if istable(dom) and ifObj(rPr2) then - class(TSXml).UpdateNode(rPr2, dom[0]['attributes'], dom[0]['children']); - End; -End; - -//w:tabs -Type TTabStops = Class(DocObject, TTabStopsImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Class(TTabStopsImpl).Create(nil, 'w:tabs'); - tabArr := array(); - if ifObj(node) then Begin - parent_ := node.Parent(); - node_ := node; - n := node_.FirstChildElement('w:tab'); - while ifObj(n) do Begin - tab := new TTabStop(); - tabArr[ length(tabArr) ] := array("field":"TTabStop", "name":"w:tab", "obj":tab, "attrEx":"", "nodeType":"", "node":n); - n := n.NextElement(); - End; - Tabs := tabArr; - InitRootNode(node); - End; - End; - - Function Create(parentObj, name);overload; - Begin - Class(TTabStopsImpl).Create(parentObj, name); - tabArr := array(); - End; - - ///删除制表符 - ///ind:integer,索引 - Function Clear(ind); - Begin - if ind>=0 and ind < length(Tabs) then Begin - if ifObj(Tabs[i]['node']) then - node_.DeleteChild(Tabs[i]['node']); - Tabs := select * from Tabs where thisrowindex <> ind end; - End; - End; - - ///添加制表符 - ///ind:integer,索引 - ///tab:TTabStop对象 - Function Add(ind, tab); - Begin - a := array("field":"TTabStop", "name":"w:tab", "obj":tab, "attrEx":"", "nodeType":"", "node":nil); - if ind = 0 then Begin - if ifObj(node_) then - a['node'] := node_.InsertFirstChild('element', 'w:tab'); - Tabs := array(a) union Tabs; - End - else if ind < 0 or ind >= length(Tabs) then Begin - if ifObj(node_) then - a['node'] := node_.InsertEndChild('element', 'w:tab'); - Tabs union= array(a); - End - else Begin - node := Tabs[length(Tabs)-1]['node']; - if length(Tabs) and ifObj(node) then - a['node'] := node_.InsertAfterChild(node, 'element', 'w:tab'); - arr := Tabs[:ind-1,:]; - arr[ length(arr) ] := a; - b := Tabs[ind:,:]; - Tabs := arr union b; - End; - if ifObj(a['node']) then Begin - arr := tab.Marshal(); - class(TSXml).UpdateNode(a['node'], arr['attributes'], arr['children']); - End; - return tab; - End; - - ///获取制表符 - ///返回:TTabStop对象 - Function Get(ind); - Begin - if ind >= 0 or ind < length(Tabs) then - return Tabs[ind]['obj']; - return nil; - End; - - ///获取全部制表符列表 - ///返回:TTabStop对象列表,array(TTab...) - Function TabStops(); - Begin - return sselect ['obj'] from Tabs end; - End; - - ///刷新制表符 - Function Flush(); - Begin - if ifObj(node_) then Begin - for i:=0 to length(Tabs)-1 do Begin - arr := Tabs[i]['obj'].Marshal(); - class(TSXml).UpdateNode(Tabs[i]['node'], arr['attributes'], arr['children']); - End; - End; - End; -End; - -//w:r -Type TRun = Class(DocObject, TRunImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Init(node); - End; - - Function Create(pNode, name);overload; - Begin - Class(TRunImpl).Create(nil, 'w:r'); - End; - - Function Init(node); - Begin - node_ := node; - name_ := 'w:r'; - Class(TRunImpl).Create(nil, 'w:r'); - InitRootNode(node); - End; - - Property Font read readFont; - Function readFont(); - Begin - return rPr; - End; - - ///应用格式 - Function Apply(); override; - Begin - arr := Marshal(); - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - End; - - ///添加tab - Function AddTab(); - Begin - n := node_.InsertFirstChild('element', 'w:tab'); - End; - - ///添加文字 - ///[isUtf8]:可选参数,当前字符集是否utf8,缺省false - Function AddText(txt, isUtf8); - Begin - str := txt; - if not isUtf8 and not class(TSXml).IsUtf8() then - str := class(TSXml).CurCodePageToUtf8(txt); - if ifObj(node_) then Begin - _insertText(str, false); - return; - End; - lines := str2array(str,'\n'); - T := lines[0]; - if _preserve(T) then - Space := 'preserve'; - for i:=1 to length(lines)-1 do Begin - NewChildNode( array("field":"", "name":"w:br", "obj":1, "attrEx":"", "nodeType":"empty") ); - NewChildNode( array("field":"", "name":"w:t", "obj":lines[i], "attrEx":"", "nodeType":"pcdata") ); - if _preserve(lines[i]) then - NewChildNode( array("field":"", "name":"w:t", "obj":'preserve', "attrEx":"xml:space", "nodeType":"") ); - End; - End; - - ///修改文字 - ///[isUtf8]:可选参数,当前字符集是否utf8,缺省false - Function SetText(txt, isUtf8); - Begin - str := txt; - if not isUtf8 and not class(TSXml).IsUtf8() then - str := class(TSXml).CurCodePageToUtf8(txt); - if ifObj(node_) then Begin - ClearText();//删除原来文字 - _insertText(str, false);//添加文字 - return; - End; - ExtNodes := array(); - T := nil; - AddText(str, true); - End; - - Function _insertText(txt, first); - Begin - lines := str2array(txt,'\n'); - for i:=0 to length(lines)-1 do Begin - t := TrimRight(lines[i]); - if i=0 then Begin - if first then - tNode := node_.InsertFirstChild('element', 'w:t', t); - else - tNode := node_.InsertEndChild('element', 'w:t', t); - End - else Begin - tNode := node_.InsertAfterChild(tNode, 'element', 'w:br');//换行符号 - tNode := node_.InsertAfterChild(tNode, 'element', 'w:t', t); - End; - End; - End; - - ///文字内容 - Function Text();override; - Begin - txt := ''; - tNode := node_.FirstChildElement(); - while ifObj(tNode) do Begin - name := tNode.GetName(); - if name = 'w:t' or name = 'w:delText' then - txt += tNode.GetText(); - //if name = 'w:br' then - // txt += '\n'; - tNode := tNode.NextElement(); - End; - if not class(TSXml).IsUtf8() then - return class(TSXml).Utf8ToCurCodePage(txt); - return txt; - End; - - ///清除字体格式 - Function ClearFormat(); - Begin - rpr_node := node_.FirstChildElement('w:rPr'); - if ifObj(rpr_node) then - node_.DeleteChild(rpr_node); - End; - - Function CopyFontFormat(fromRun); - Begin - ClearFormat(); - rpr_node := fromRun.node_.FirstChildElement('w:rPr'); - if not ifObj(rpr_node) then - return; - - data := rpr_node.Marshal(); - node_.InsertFirstChild(data[0]); - End; - - ///清除全部文字内容 - Function ClearText(); - Begin - if ifObj(node_) then Begin - n := node_.FirstChildElement('w:t'); - while ifObj(n) do Begin - next := n.NextElement('w:t'); - node_.DeleteChild(n); - n := next; - End; - End; - End; - -End; - -Type TPicture = Class(DocObject, TPictureImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Init(node); - End; - - Function Init(node); - Begin - node_ := node; - name_ := 'w:p'; - Width := 0.; - Height := Width; - Class(TPictureImpl).Create(nil, 'w:p'); - InitRootNode(node); - End; - - Property Format read readFormat; - Function readFormat(); - Begin - return Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr; - End; - - ///修改图片格式 - ///[docx]:当前文档对象,为空指当前文档 - Function Apply(docx); override; - Begin - document := docx; - if not ifObj(document) then Begin - document := TOfficeApi().GetDocument(); - if not ifObj(document) then - return; - End; - arr := Marshal(); - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - if ifBinary(Image) then Begin //修改图片内容 - node := class(TSXml).GetNode(node_,'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip'); - if ifObj(node) then - rid := node.GetAttribute('r:embed'); - xml := document.Zip().Get('word/_rels/document.xml.rels'); - picFileName := class(TSXml).FindRelationshipTarget(xml, rid); - if ifstring(picFileName) then Begin - pic := document.Zip().Get('word/' + picFileName); - if ifObj(pic) then - pic.Data := Image; - End; - End; - End; - - Function ScaledDimensions(image); - Begin - ETU := 360045;//1cm单位 - maxX := 17.0;//水平方向17cm - maxY := 23.0;//垂直方向23cm - imageW := image.Width() / 28.346 * ETU; - imageH := image.Height() / 28.346 * ETU; - if Width <= 0 and Height <= 0 then Begin //图像缺省大小 - widthVal := imageW; - heightVal := imageH; - End - else Begin //用户设置了图片尺寸 - widthVal := ETU * Width; - heightVal := ETU * Height; - if Width <= 0 and imageH and imageW then Begin //按照图片比例自动缩放 - scaling_factor := imageW / imageH; - widthVal := round(heightVal * scaling_factor); - End; - - if Height <= 0 and imageH and imageW then Begin //按照图片比例自动缩放 - scaling_factor := imageW / imageH; - heightVal := round(widthVal / scaling_factor); - End; - End; - //缺省大小(用户没有设置尺寸,同时TSImage也没有识别图片尺寸) - if widthVal = 0 and heightVal = 0 then - widthVal := 15 * ETU; - if widthVal = 0 then - widthVal := heightVal * 2; - if heightVal = 0 then - heightVal := widthVal / 3; - - //缩放 - ratio := 1; - if widthVal > maxX * ETU then - ratio := maxX * ETU / widthVal; - if heightVal > maxY * ETU then Begin - r2 := maxY * ETU / heightVal; - if r2 < ratio then - ratio := r2; - End; - if ratio < 1 then Begin - heightVal *= ratio; - widthVal *= ratio; - End; - //println('w={}-{},maxx={}, h={}-{},maxh={},ratio={}',integer(imageW),integer(widthVal),15 * ETU, integer(imageH),integer(heightVal),23 * ETU,ratio); - return array(integer(widthVal), integer(heightVal)); - End; - - Image;//图片内容(Binary) - Descr; - Width;//厘米 - Height;//厘米 -End; - -Type TChart = Class(TChartImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Class(TChartImpl).Create(nil, 'w:p'); - pNode := node; - self.C := true; - InitRootNode(node); - End; - - Function Init(docx, node, cNode); - Begin - pNode := node; - if not ifObj(cNode) then - return; - IsWord_ := docx.IsWord(); - rId := cNode.GetAttribute('r:id'); - relsObj := docx.Zip().Get('word/_rels/document.xml.rels'); - Target := class(TSXml).FindRelationshipTarget(relsObj, rId); - if ifNil(Target) then - return; - chartFileName := getChartFileName(Target); - xmlObj := docx.Zip().Get(chartFileName); - if not ifObj(xmlObj) then - return; - plotAreaNode := class(TSXml).GetNode(xmlObj, 'c:chartSpace/c:chart/c:plotArea'); - if ifObj(plotAreaNode) then Begin - child := plotAreaNode.FirstChildElement(); - while ifObj(child) do Begin - nodename := child.GetName(); - if rightstr(nodename,5) = 'Chart' then Begin - if leftstr(nodename,2) = 'c:' then - self.C := true; - ChartNode := child; - break; - End; - child := child.NextElement(); - End; - End; - End; - - Function Serialize(isWord); - Begin - Plotarea := TOfficeObj('TPlotarea'); - Plotarea.Layout := true; - isWord_ := isWord; - Type := lowercase(Type); - case Type of - 'area','areastacked','areapercentstacked','area3d','area3dstacked','area3dpercentstacked','bar','barstacked','barpercentstacked', - 'bar3dclustered','bar3dstacked','bar3dpercentstacked','bar3dconeclustered','bar3dconestacked','bar3dconepercentstacked', - 'bar3dpyramidclustered','bar3dpyramidstacked','bar3dpyramidpercentstacked','bar3dcylinderclustered','bar3dcylinderstacked', - 'bar3dcylinderpercentstacked','col','colstacked','colpercentstacked','col3d','col3dclustered','col3dstacked','col3dpercentstacked', - 'col3dcone','col3dconeclustered','col3dconestacked','col3dconepercentstacked','col3dpyramid','col3dpyramidclustered', - 'col3dpyramidstacked','col3dpyramidpercentstacked','col3dcylinder','col3dcylinderclustered','col3dcylinderstacked', - 'col3dcylinderpercentstacked','bubble','bubble3d': - drawBaseChart(Plotarea); - 'doughnut': - Begin - drawExtChart(Plotarea, 'c:doughnutChart'); - Plotarea.chart.HoleSize := 75; - End - 'line': - drawLineChart(Plotarea); - 'pie3d': - drawExtChart(Plotarea, 'c:pie3DChart'); - 'pie': - drawExtChart(Plotarea, 'c:pieChart'); - 'pieofpiechart': - Begin - drawExtChart(Plotarea, 'ofPieChart'); - Plotarea.chart.OfPieType := 'pie'; - End - 'barofpiechart': - Begin - drawExtChart(Plotarea, 'c:ofPieChart'); - Plotarea.chart.OfPieType := 'bar'; - End - 'radar': - drawRadarChart(Plotarea); - 'scatter': - drawScatterChart(Plotarea); - 'surface3d','wireframesurface3d': - drawSurface3DChart(Plotarea, 'c:surface3DChart'); - 'contour','wireframecontour': - drawSurface3DChart(Plotarea, 'c:surfaceChart'); - End; - Plotarea.SpPr.noFill := true; - Plotarea.SpPr.Ln.noFill := true; - Plotarea.SpPr.EffectLst := true; - End; - - ///添加图表Series数据 - Function AddSeries(Name, Categories, Value); - Begin - SerName := name; - catArr := Categories; - if not class(TSXml).IsUtf8() then Begin - if name and ifstring(name) then - SerName := class(TSXml).CurCodePageToUtf8(name); - if ifstring(catArr) then - catArr := class(TSXml).CurCodePageToUtf8(catArr); - else if istable(catArr) then Begin - for i:=0 to length(catArr)-1 do Begin - if ifstring(catArr[i]) then - catArr[i] := class(TSXml).CurCodePageToUtf8(catArr[i]); - End; - End; - End; - - Series union= array(("Name":SerName,"Categories":catArr,"Values":Value)); - return length(Series); - End; - - ///清除图表Series数据 - Function ClearSeries(); - Begin - Series := array(); - End; - - ///删除图表Series数据 - Function RemoveSeries(i); - Begin - cnt := length(Series); - if i < 0 or i >= cnt then - return length(Series); - - tmp := Series[:i-1,:]; - tmp union= Series[i+1:,:]; - Series := tmp; - return length(Series); - End; - - Function NewExcelFile(); - Begin - Excel := new TSExcelFile(); - [err, errmsg] := Excel.NewFile(); - if err then - Excel := nil; - End; - - ///更新图表 - Function Apply(docx); - Begin - if not ifObj(ChartNode) then - return; - if ifstring(Title) and Title <> '' then - UpdateTitle(class(TSXml).CurCodePageToUtf8(Title)); - //不同的图表,数据区较复杂 - if not istable(Series) then return; - ser := self.C ? 'c:ser' : 'ser'; - serNode := ChartNode.FirstChildElement(ser); - if not ifObj(serNode) then return;//没有缺省数据 - //存在Excel扩展数据文件 - node := xmlObj.FirstChildElement('c:chartSpace').FirstChildElement('c:externalData'); - if ifObj(node) then Begin - rId := node.GetAttribute('r:id'); - fName := ExtractFileName(chartFileName); - rels := 'word/charts/_rels/' + fName + '.rels'; - chartId := leftstr(fName, length(fName) - 4); - chartId := rightstr(chartId, length(chartId) - 5); - relsObj := docx.Zip().Get(rels); - if ifObj(relsObj) then Begin - target := class(TSXml).FindRelationshipTarget(relsObj, rId);//../embeddings/Workbook2.xlsx - excelFileName := ReplaceStr(target, '..','word'); - excelObj := docx.Zip().Get(excelFileName); - if ifObj(excelObj) then - NewExcelFile(); - End; - End; - - //更新数据区 - dom := serNode.Marshal(); - for i:=0 to length(Series)-1 do Begin - if i then - serNode := serNode.InsertAfterChild(serNode, dom[0]); - removeOldSer(serNode); - ser := TOfficeObj('TSer'); - ser.IDx := i; - ser.Ord := i; - setTx(ser.Tx.StrRef, Series[i]['Name'], i); - n := serNode.FirstChildElement('c:cat'); - if ifObj(n) then Begin - _setCat(ser.Cat, i); - _setVal(ser.Val, i); - End; - - n := serNode.FirstChildElement('c:xVal'); - if ifObj(n) then Begin - _setCat(ser.XVal, i); - _setVal(ser.YVal, i); - End; - updData := ser.Marshal(); - class(TSXml).UpdateNode(serNode, updData['attributes'], updData['children']); - End; - - //删除多余的 - node := serNode.NextElement(ser); - while ifObj(node) do Begin - ChartNode.DeleteChild(node); - node := serNode.NextElement(ser); - End; - - //修改内嵌的excel文件 - AddExcelFile(docx, xmlObj, chartId); - End; - - Function removeOldSer(node); - Begin - task := array('c:tx','c:cat','c:val','c:xVal','c:xYal'); - for i:=0 to length(task)-1 do begin - n := node.FirstChildElement(task[i]); - if ifObj(n) then - n.DeleteChildren(); - End; - End; - - Function AddExcelFile(docx, chartXml, chartId); - Begin - //内嵌excel数据文件 - if not ifObj(Excel) then - return; - [err, data] := Excel.Zip().Save2Mem(); - if err then - return; - rId := 'rId1'; - workBook := 'embeddings/Workbook1.xlsx'; - fileCnt := 1 + vselect countof( ['FileName'] ) from docx.Zip().Files() where AnsiStartsText('word/embeddings/Workbook', ['FileName']) end; - ctXml := docx.Zip().Get('[Content_Types].xml'); - class(TSXml).AddDefaultContentType(ctXml, 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - externalDataNode := chartXml.FirstChildElement('c:chartSpace').FirstChildElement('c:externalData'); - if not ifObj(externalDataNode) then - chartXml.FirstChildElement('c:chartSpace').InsertEndChild(''); - else Begin - rId := externalDataNode.GetAttribute('r:id'); - End; - rels := 'word/charts/_rels/chart' $ chartId $ '.xml.rels'; - relsObj := docx.Zip().Get(rels); - if not ifObj(relsObj) then Begin - rId := 'rId1'; - xmlStr := ' - - -'; - docx.Zip().Add(rels, xmlStr); - if fileCnt > 1 then Begin - workBook := 'embeddings/Workbook' $ fileCnt $ '.xlsx'; - relsObj := docx.Zip().Get(rels); - node := relsObj.FirstChildElement('Relationships').FirstChildElement('Relationship'); - node.SetAttribute('Target', '../' + workBook); - End; - End - else Begin - target := class(TSXml).FindRelationshipTarget(relsObj, rId); - if ifNil(target) then Begin - [maxRid, tg, id] := class(TSXml).FindRelationshipRid(relsObj,''); - if fileCnt > 1 then - workBook := 'embeddings/Workbook' $ fileCnt $ '.xlsx'; - maxRid ++; - class(TSXml).AddRelationshipRid(relsObj, '../' + workBook, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package', 'rId' $ maxRid, nil); - End - else - workBook := ReplaceStr(target, '../', ''); - End; - xlsx := docx.Zip().Get('word/' + workBook); - if ifObj(xlsx) then - xlsx.Data := data; //更新xlsx文件 - else - docx.Zip().Add('word/' + workBook, data); //添加xlsx文件 - End; - - ///修改图表标题 - Function UpdateTitle(t); - Begin - task := array('c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t', 'pcdata', t); - class(TSXml).SetNodeValue(ChartNode.Root(), task); - End; - - ///显示数据表 - ///b:bool型,是否显示数据表 - Function ShowDataTable(b); - Begin - if not ifObj(plotAreaNode) then - return; - node := plotAreaNode.FirstChildElement('c:dTable'); - if ifObj(node) then - plotAreaNode.DeleteChild(node); - if not b then - return; - xmlStr := ' - - - - - - - - - - - - - - - - - - - - - '; - plotAreaNode.InsertEndChild(xmlStr); - End; -private - Function getChartFileName(f); - Begin - if leftstr(f,5) = 'word/' then - return f; - if leftstr(f,3) = '../' then - return 'word/' + f[4:]; - if f[1] = '/' then - return f[2:]; - if leftstr(f,7) = 'charts/' then - return 'word/' + f; - return f; - End; - - Function updateValue(task); - Begin - for i:=0 to length(task)-1 do Begin - if not C then - task[i][0] := ReplaceStr(task[i][0], 'c:', ''); - class(TSXml).SetNodeValue(xmlObj_, task[i]); - End; - End; - - Function getLegendPosition(t); - Begin - m := array("bottom": "b", - "left": "l", - "right": "r", - "top": "t", - "top_right": "tr"); - return m[t]; - End; - - Function drawSurface3DChart(o, name); - Begin - o.chart.NodeName := name; - setChartSer(o); - o.chart.Axid := 754001152; - o.chart.Axid2 := 753999904; - o.chart.Axid3 := 832256642; - setCatAx(o.CatAx); - setValAx(o.ValAx); - setSerAx(o.SerAx); - if Type in array( 'wireframesurface3d', 'wireframecontour' ) then - o.chart.Wireframe := true; - End; - - Function drawScatterChart(o); - Begin - o.chart.NodeName := 'c:scatterChart'; - o.chart.ScatterStyle := 'smoothMarker'; - o.chart.VaryColors := false; - setChartSer(o); - setDLbls(o.chart.DLbls); - o.chart.Axid := 754001152; - o.chart.Axid2 := 753999904; - setCatAx(o.CatAx); - setValAx(o.ValAx); - End; - - Function drawRadarChart(o); - Begin - o.chart.NodeName := 'c:radarChart'; - o.chart.RadarStyle := 'marker'; - o.chart.VaryColors := false; - setChartSer(o); - setDLbls(o.chart.DLbls); - o.chart.Axid := 754001152; - o.chart.Axid2 := 753999904; - setCatAx(o.CatAx); - setValAx(o.ValAx); - End; - - Function drawExtChart(o, name); - Begin - o.chart.NodeName := name; - o.chart.VaryColors := VaryColors; - setChartSer(o); - setDLbls(o.chart.DLbls); - End; - - Function drawLineChart(o); - Begin - o.chart.NodeName := 'c:lineChart'; - o.chart.Grouping := getGrouping(Type); - o.chart.VaryColors := false; - setChartSer(o); - setDLbls(o.chart.DLbls); - o.chart.Smooth := false; - o.chart.Axid := 754001152; - o.chart.Axid2 := 753999904; - setCatAx(o.CatAx); - setValAx(o.ValAx); - End; - - Function drawBaseChart(o); - Begin - o.chart.BarDir := getBarDir(Type); - o.chart.Grouping := getGrouping(Type); - o.chart.VaryColors := VaryColors; - o.chart.Overlap := getVaryColors(Type); - o.chart.Axid := 754001152; - o.chart.Axid2 := 753999904; - o.chart.NodeName := getChartName(Type); - setChartSer(o); - o.chart.Shape := getSharp(Type); - setDLbls(o.chart.DLbls); - setCatAx(o.CatAx); - setValAx(o.ValAx); - End; - - Function setSerAx(SerAx); - Begin - SerAx.AxID := 832256642; - SerAx.Scaling.Max := YAxis.Max; - SerAx.Scaling.Min := YAxis.Min; - SerAx.Scaling.Orientation := YAxis.ReverseOrder ? 'maxMin' : 'minMax'; - SerAx.Del := YAxis.None; - SerAx.AxPos := XAxis.ReverseOrder ? 't' : 'b'; - SerAx.TickLblPos := 'nextTo'; - drawPlotAreaSpPr(SerAx.SpPr); - drawPlotAreaTxPr(SerAx.TxPr); - SerAx.CrossAx := 753999904; - End; - - Function setCatAx(CatAx); - Begin - CatAx.AxID := 754001152; - CatAx.Scaling.Max := XAxis.Max; - CatAx.Scaling.Min := XAxis.Min; - CatAx.Scaling.Orientation := XAxis.ReverseOrder ? 'maxMin' : 'minMax'; - CatAx.Del := 0;//XAxis.None; - CatAx.AxPos := XAxis.ReverseOrder ? 't' : 'b'; - CatAx.NumFmt.FormatCode := 'General'; - CatAx.NumFmt.SourceLinked := true; - CatAx.MajorTickMark := 'none'; - CatAx.MinorTickMark := 'none'; - CatAx.TickLblPos := 'nextTo'; - drawPlotAreaSpPr(CatAx.SpPr); - drawPlotAreaTxPr(CatAx.TxPr); - CatAx.CrossAx := 753999904; - CatAx.Crosses := 'autoZero'; - CatAx.Auto := true; - CatAx.LblAlgn := 'ctr'; - CatAx.LblOffset := 100; - CatAx.NoMultiLvlLbl := false; - if XAxis.MajorGridlines then - drawPlotAreaSpPr(CatAx.MajorGridlines.SpPr); - if XAxis.MinorGridlines then - drawPlotAreaSpPr(CatAx.MinorGridlines.SpPr); - if XAxis.TickLabelSkip then - CatAx.TickLabelSkip := XAxis.TickLabelSkip; - End; - - Function setValAx(ValAx); - Begin - ValAx.AxID := 753999904; - ValAx.Scaling.Max := YAxis.Max; - ValAx.Scaling.Min := YAxis.Min; - if ifint(YAxis.LogBase) and YAxis.LogBase >= 2 and YAxis.LogBase <= 1000 then - ValAx.Scaling.LogBase := YAxis.LogBase; - ValAx.Scaling.Orientation := YAxis.ReverseOrder ? 'maxMin' : 'minMax'; - ValAx.Del := YAxis.None; - ValAx.AxPos := YAxis.ReverseOrder ? 'r' : 'l'; - ValAx.NumFmt.FormatCode := chartValAxNumFmtFormatCode(Type); - ValAx.NumFmt.SourceLinked := true; - ValAx.MajorTickMark := 'none'; - ValAx.MinorTickMark := 'none'; - ValAx.TickLblPos := 'nextTo'; - drawPlotAreaSpPr(ValAx.SpPr); - drawPlotAreaTxPr(ValAx.TxPr); - ValAx.CrossAx := 754001152; - ValAx.Crosses := 'autoZero'; - ValAx.CrossBetween := chartValAxCrossBetween(Type); - if XAxis.MajorGridlines then - drawPlotAreaSpPr(ValAx.MajorGridlines.SpPr); - if XAxis.MinorGridlines then - drawPlotAreaSpPr(ValAx.MinorGridlines.SpPr); - ValAx.MajorUnit := YAxis.MajorUnit; - if Type in array('contour', 'wireframecontour') then - ValAx.TickLblPos := 'none'; - End; - - Function chartValAxCrossBetween(t); - Begin - m := array( - 'area': 'midCat', - 'areastacked': 'midCat', - 'areapercentstacked': 'midCat', - 'area3d': 'midCat', - 'area3dstacked': 'midCat', - 'area3dpercentstacked': 'midCat', - 'bar': 'between', - 'barstacked': 'between', - 'barpercentstacked': 'between', - 'bar3dclustered': 'between', - 'bar3dstacked': 'between', - 'bar3dpercentstacked': 'between', - 'bar3dconeclustered': 'between', - 'bar3dconestacked': 'between', - 'bar3dconepercentstacked': 'between', - 'bar3dpyramidclustered': 'between', - 'bar3dpyramidstacked': 'between', - 'bar3dpyramidpercentstacked': 'between', - 'bar3dcylinderclustered': 'between', - 'bar3dcylinderstacked': 'between', - 'bar3dcylinderpercentstacked': 'between', - 'col': 'between', - 'colstacked': 'between', - 'colpercentstacked': 'between', - 'col3d': 'between', - 'col3dclustered': 'between', - 'col3dstacked': 'between', - 'col3dpercentstacked': 'between', - 'col3dcone': 'between', - 'col3dconeclustered': 'between', - 'col3dconestacked': 'between', - 'col3dconepercentstacked': 'between', - 'col3dpyramid': 'between', - 'col3dpyramidclustered': 'between', - 'col3dpyramidstacked': 'between', - 'col3dpyramidpercentstacked': 'between', - 'col3dcylinder': 'between', - 'col3dcylinderclustered': 'between', - 'col3dcylinderstacked': 'between', - 'col3dcylinderpercentstacked': 'between', - 'doughnut': 'between', - 'line': 'between', - 'pie': 'between', - 'pie3d': 'between', - 'pieofpiechart': 'between', - 'barofpiechart': 'between', - 'radar': 'between', - 'scatter': 'between', - 'surface3d': 'midCat', - 'wireframesurface3d': 'midCat', - 'contour': 'midCat', - 'wireframecontour': 'midCat', - 'bubble': 'midCat', - 'bubble3d': 'midCat'); - return m[t]; - End; - - Function chartValAxNumFmtFormatCode(t); - Begin - m := array( - 'area': 'General', - 'areastacked': 'General', - 'areapercentstacked': '0%', - 'area3d': 'General', - 'area3dstacked': 'General', - 'area3dpercentstacked': '0%', - 'bar': 'General', - 'barstacked': 'General', - 'barpercentstacked': '0%', - 'bar3dclustered': 'General', - 'bar3dstacked': 'General', - 'bar3dpercentstacked': '0%', - 'bar3dconeclustered': 'General', - 'bar3dconestacked': 'General', - 'bar3dconepercentstacked': '0%', - 'bar3dpyramidclustered': 'General', - 'bar3dpyramidstacked': 'General', - 'bar3dpyramidpercentstacked': '0%', - 'bar3dcylinderclustered': 'General', - 'bar3dcylinderstacked': 'General', - 'bar3dcylinderpercentstacked': '0%', - 'col': 'General', - 'colstacked': 'General', - 'colpercentstacked': '0%', - 'col3d': 'General', - 'col3dclustered': 'General', - 'col3dstacked': 'General', - 'col3dpercentstacked': '0%', - 'col3dcone': 'General', - 'col3dconeclustered': 'General', - 'col3dconestacked': 'General', - 'col3dconepercentstacked': '0%', - 'col3dpyramid': 'General', - 'col3dpyramidclustered': 'General', - 'col3dpyramidstacked': 'General', - 'col3dpyramidpercentstacked': '0%', - 'col3dcylinder': 'General', - 'col3dcylinderclustered': 'General', - 'col3dcylinderstacked': 'General', - 'col3dcylinderpercentstacked': '0%', - 'doughnut': 'General', - 'line': 'General', - 'pie': 'General', - 'pie3d': 'General', - 'pieofpiechart': 'General', - 'barofpiechart': 'General', - 'radar': 'General', - 'scatter': 'General', - 'surface3d': 'General', - 'wireframesurface3d': 'General', - 'contour': 'General', - 'wireframecontour': 'General', - 'bubble': 'General', - 'bubble3d': 'General'); - return m[t]; - End; - - Function drawPlotAreaTxPr(TxPr); - Begin - TxPr.BodyPr.Rot := -60000000; - TxPr.BodyPr.SpcFirstLastPara := true; - TxPr.BodyPr.VertOverflow := 'ellipsis'; - TxPr.BodyPr.Vert := 'horz'; - TxPr.BodyPr.Wrap := 'square'; - TxPr.BodyPr.Anchor := 'ctr'; - TxPr.BodyPr.AnchorCtr := true; - TxPr.P.PPr.DefRPr.Sz := 900; - TxPr.P.PPr.DefRPr.Bold := false; - TxPr.P.PPr.DefRPr.Italic := false; - TxPr.P.PPr.DefRPr.U := 'none'; - TxPr.P.PPr.DefRPr.Strike := 'noStrike'; - TxPr.P.PPr.DefRPr.Kern := 1200; - TxPr.P.PPr.DefRPr.Baseline := 0; - TxPr.P.PPr.DefRPr.SolidFill.SchemeClr.Val := 'tx1'; - TxPr.P.PPr.DefRPr.SolidFill.SchemeClr.LumMod := 15000; - TxPr.P.PPr.DefRPr.SolidFill.SchemeClr.LumOff := 85000; - TxPr.P.PPr.DefRPr.Latin.Typeface := '+mn-lt'; - TxPr.P.PPr.DefRPr.Ea.Typeface := '+mn-ea'; - TxPr.P.PPr.DefRPr.Cs.Typeface := '+mn-cs'; - TxPr.P.EndParaRPr.Lang := 'en-US'; - End; - - Function drawPlotAreaSpPr(SpPr); - Begin - SpPr.Ln.W := 9525; - SpPr.Ln.Cap := 'flat'; - SpPr.Ln.Cmpd := 'sng'; - SpPr.Ln.Algn := 'ctr'; - SpPr.Ln.SolidFill.SchemeClr.Val := 'tx1'; - SpPr.Ln.SolidFill.SchemeClr.LumMod := 15000; - SpPr.Ln.SolidFill.SchemeClr.LumOff := 85000; - End; - - Function setChartSer(o); - Begin - SerArr := array(); - for i:=0 to length(Series)-1 do Begin - ser := TOfficeObj('TSer'); - SerArr union= array(('name':'c:ser','obj':ser,'attrEx':'','nodeType':'','attrName':'')); - ser.IDx := i + Ord; - ser.Ord := i + Ord; - setTx(ser.Tx.StrRef, Series[i]['Name'], i); - setSpPr(ser.SpPr, i); - setMarker(ser.Marker, i); - setDpt(ser, i); - //setDLbls(ser.DLbls); - //ser.Dlbls.Del := 1; - //ser.InvertIfNegative := false; - setCat(ser.Cat, i); - setVal(ser.Val, i); - setXVal(ser.XVal, i); - setYVal(ser.YVal, i); - setBubbleSize(ser.BubbleSize, i); - setBubble3D(ser, i); - End; - o.chart.Ser := SerArr; - End; - - Function _setExcelCellVal(cell, v); - Begin - //v is utf8 - if ifObj(Excel) then Begin - Excel.SetCellValue('Sheet1', cell, class(TSXml).Utf8ToCurCodePage(v)); - End; - End; - - Function setTx(strRef, name, i); - Begin - if not IsWord_ then Begin - strRef.F := name; - return; - End; - [err, col] := ColumnNumberToName(i + 2); - strRef.F := 'Sheet1!$' $ col $ '$1'; - strRef.strCache.ptCount := 1; - strRef.strCache.pt.IDx := 0; - strRef.strCache.pt.V := name; - _setExcelCellVal(col $ '1', name); - End; - - Function setBubble3D(ser, i); - Begin - if Type <> 'bubble3d' then return; - ser.Bubble3D := true; - End; - - Function setBubbleSize(BubbleSize, i); - Begin - if not (Type in array('bubble', 'bubble3d')) then return; - _setVal(BubbleSize, i); - End; - - Function setYVal(Val, i); - Begin - if not (Type in array('scatter', 'bubble', 'bubble3d')) then return; - _setVal(Val, i); - End; - - Function setXVal(xVal, i); - Begin - if not (Type in array('scatter')) then return; - _setCat(xVal, i); - End; - - Function setVal(Val, ind); - Begin - if Type in array('scatter', 'bubble', 'bubble3d') then return; - _setVal(Val, ind); - End; - - Function _setVal(Val, ind); - Begin - data := Series[ind]['Values']; - if ifstring(data) then - Val.NumRef.F := data; //excel图表(Sheet1!$C$2:$C$6) - else if istable(data) then Begin //word 图表 - cnt := length(data); - //[err, axis] := ColumnNumberToName(2 * ind + 2); - [err, axis] := ColumnNumberToName(ind + 2); - Val.NumRef.F := format('Sheet1!$%s$2:$%s$%d', axis, axis, cnt+1); - Val.NumRef.NumCache.PtCount := cnt; - Val.NumRef.NumCache.formatCode := 'General'; - for i:=0 to cnt-1 do Begin - Tpt := TOfficeObj('Tpt'); - Tpt.IDx := i; - Tpt.V := data[i]; - //[err,cell] := CoordinatesToCellName(2*ind+2, i+2); - [err,cell] := CoordinatesToCellName(ind+2, i+2); - _setExcelCellVal(cell, data[i]); - Val.NumRef.NumCache.NewChildNode( array("field":"", "name":"c:pt", "obj":Tpt, "attrEx":"", "nodeType":"") ); - End; - End; - End; - - Function setCat(Cat, ind); - Begin - if Type in array('scatter', 'bubble', 'bubble3d') then return; - _setCat(Cat, ind); - End; - - Function _setCat(Cat, ind); - Begin - Categories := Series[ind]['Categories']; - if ifstring(Categories) then - cat.StrRef.F := Categories; //excel图表(Sheet1!$A$2:$A$6) - else if istable(Categories) then Begin //word 图表 - cnt := length(Categories); - //[err, axis] := ColumnNumberToName(2 * ind + 1); - cat.StrRef.F := format('Sheet1!$A$2:$A$%d', cnt+1); - cat.StrRef.StrCache.PtCount := cnt; - for i:=0 to cnt-1 do Begin - Tpt := TOfficeObj('Tpt'); - Tpt.IDx := i; - Tpt.V := Categories[i]; - [err,cell] := CoordinatesToCellName(2*ind+1, i+2); - if ind = 0 then - _setExcelCellVal(cell, Tpt.V); - cat.StrRef.StrCache.NewChildNode( array("field":"", "name":"c:pt", "obj":Tpt, "attrEx":"", "nodeType":"") ); - End; - End; - End; - - Function setDLbls(DLbls); - Begin - if Type in array('scatter','surface3d', 'wireframesurface3d', 'contour', 'wireframecontour', 'bubble', 'bubble3d') then - return; - DLbls.ShowLegendKey := ShowLegendKey; - DLbls.ShowVal := ShowVal; - DLbls.ShowCatName := ShowCatName; - DLbls.ShowSerName := ShowSerName; - DLbls.ShowBubbleSize := ShowBubbleSize; - DLbls.ShowPercent := ShowPercent; - DLbls.ShowLeaderLines := ShowLeaderLines; - End; - - Function setDpt(o, ind); - Begin - if not (Type in array('pie','pie3d')) then return; - data := Series[ind]['Values']; - if ifstring(data) then Begin - o.Dpt.IDx := 0; - o.Dpt.Bubble3D := false; - setPieSppr(o.Dpt.Sppr); - End - else if istable(data) then Begin - cnt := length(data); - r := array(); - for i:=0 to cnt-1 do Begin - dpt := TOfficeObj('TDpt'); - dpt.IDx := i; - dpt.Bubble3D := false; - if i=0 then - setPieSppr(dpt.sPpr); - r[length(r)] := array('name':'c:dPt','obj':dpt,'attrEx':'','nodeType':'','attrName':''); - End; - o.DptEx := r; - End; - End; - - Function setPieSppr(sPpr); - Begin - SpPr.SolidFill.SchemeClr.Val := 'accent1'; - SpPr.Ln.W := 25400; - SpPr.Ln.Cap := 'rnd'; - SpPr.Ln.SolidFill.SchemeClr.Val := 'lt1'; - SpPr.Sp3D.ContourW := 25400; - SpPr.Sp3D.ContourClr.SchemeClr.Val := 'lt1'; - End; - - Function setMarker(Marker, i); - Begin - if not (Type in array('scatter', 'line')) then return; - if Type = 'scatter' then - Marker.Symbol := 'circle'; - Marker.Size := 5; - if ifstring(Series[i]['Symbol']) then - Marker.Symbol := Series[i]['Symbol']; - if ifint(Series[i]['Size']) then - Marker.Size := Series[i]['Size']; - - if i < 6 then Begin - marker.SpPr.SolidFill.SchemeClr.Val := 'accent' $ (i + 1); - Marker.SpPr.Ln.W := 9252; - Marker.SpPr.Ln.SolidFill.SchemeClr.Val := 'accent' $ (i + 1); - End; - End; - - Function setSppr(SpPr, i); - Begin - if Type = 'line' then Begin - SpPr.Ln.algn := 'ctr'; - SpPr.Ln.cmpd := 'sng'; - SpPr.Ln.cap := 'rnd'; - SpPr.Ln.W := 8000; - //SpPr.Ln.NoFill := true; - SpPr.Ln.prstDash := 'solid'; - SpPr.Ln.round := true; - SpPr.Ln.SolidFill.SchemeClr.Val := 'accent' $ ((Ord+i)%6+1); - return; - End; - if Type = 'scatter' then Begin - w := Series[i]['LineWidth']; - SpPr.Ln.W := 0.25 > w || w > 999 ? 25400 : 12700 * w; - SpPr.Ln.Cap := 'rnd'; - SpPr.Ln.SolidFill.SchemeClr.Val := 'accent' $ ((Ord+i)%6+1); - return; - End; - End; - - Function getSharp(t); - Begin - m := array( - 'bar3dconeclustered': 'cone', - 'bar3dconestacked': 'cone', - 'bar3dconepercentstacked': 'cone', - 'bar3dpyramidclustered': 'pyramid', - 'bar3dpyramidstacked': 'pyramid', - 'bar3dpyramidpercentstacked': 'pyramid', - 'bar3dcylinderclustered': 'cylinder', - 'bar3dcylinderstacked': 'cylinder', - 'bar3dcylinderpercentstacked': 'cylinder', - 'col3dcone': 'cone', - 'col3dconeclustered': 'cone', - 'col3dconestacked': 'cone', - 'col3dconepercentstacked': 'cone', - 'col3dpyramid': 'pyramid', - 'col3dpyramidclustered': 'pyramid', - 'col3dpyramidstacked': 'pyramid', - 'col3dpyramidpercentstacked': 'pyramid', - 'col3dcylinder': 'cylinder', - 'col3dcylinderclustered': 'cylinder', - 'col3dcylinderstacked': 'cylinder', - 'col3dcylinderpercentstacked': 'cylinder'); - return m[t]; - End; - - Function getChartName(t); - Begin - m := array( - 'area': 'areaChart', - 'areastacked': 'areaChart', - 'areapercentstacked': 'areaChart', - 'area3d': 'area3DChart', - 'area3dstacked': 'area3DChart', - 'area3dpercentstacked': 'area3DChart', - 'bar': 'barChart', - 'barstacked': 'barChart', - 'barpercentstacked': 'barChart', - 'bar3dclustered': 'bar3DChart', - 'bar3dstacked': 'bar3DChart', - 'bar3dpercentstacked': 'bar3DChart', - 'bar3dconeclustered': 'bar3DChart', - 'bar3dconestacked': 'bar3DChart', - 'bar3dconepercentstacked': 'bar3DChart', - 'bar3dpyramidclustered': 'bar3DChart', - 'bar3dpyramidstacked': 'bar3DChart', - 'bar3dpyramidpercentstacked': 'bar3DChart', - 'bar3dcylinderclustered': 'bar3DChart', - 'bar3dcylinderstacked': 'bar3DChart', - 'bar3dcylinderpercentstacked': 'bar3DChart', - 'col': 'barChart', - 'colstacked': 'barChart', - 'colpercentstacked': 'barChart', - 'col3d': 'bar3DChart', - 'col3dclustered': 'bar3DChart', - 'col3dstacked': 'bar3DChart', - 'col3dpercentstacked': 'bar3DChart', - 'col3dcone': 'bar3DChart', - 'col3dconeclustered': 'bar3DChart', - 'col3dconestacked': 'bar3DChart', - 'col3dconepercentstacked': 'bar3DChart', - 'col3dpyramid': 'bar3DChart', - 'col3dpyramidclustered': 'bar3DChart', - 'col3dpyramidstacked': 'bar3DChart', - 'col3dpyramidpercentstacked': 'bar3DChart', - 'col3dcylinder': 'bar3DChart', - 'col3dcylinderclustered': 'bar3DChart', - 'col3dcylinderstacked': 'bar3DChart', - 'col3dcylinderpercentstacked': 'bar3DChart', - 'bubble': 'bubbleChart', - 'bubble3d': 'bubbleChart'); - return 'c:' $ m[t]; - End; - - Function getVaryColors(t); - Begin - m := array( - 'barstacked': 100, - 'barpercentstacked': 100, - 'colstacked': 100, - 'colpercentstacked': 100 - ); - return m[t]; - End; - - Function getGrouping(t); - Begin - m := array( - 'area': 'standard', - 'areastacked': 'stacked', - 'areapercentstacked': 'percentStacked', - 'area3d': 'standard', - 'area3dstacked': 'stacked', - 'area3dpercentstacked': 'percentStacked', - 'bar': 'clustered', - 'barstacked': 'stacked', - 'barpercentstacked': 'percentStacked', - 'bar3dclustered': 'clustered', - 'bar3dstacked': 'stacked', - 'bar3dpercentstacked': 'percentStacked', - 'bar3dconeclustered': 'clustered', - 'bar3dconestacked': 'stacked', - 'bar3dconepercentstacked': 'percentStacked', - 'bar3dpyramidclustered': 'clustered', - 'bar3dpyramidstacked': 'stacked', - 'bar3dpyramidpercentstacked': 'percentStacked', - 'bar3dcylinderclustered': 'clustered', - 'bar3dcylinderstacked': 'stacked', - 'bar3dcylinderpercentstacked': 'percentStacked', - 'col': 'clustered', - 'colstacked': 'stacked', - 'colpercentstacked': 'percentStacked', - 'col3d': 'standard', - 'col3dclustered': 'clustered', - 'col3dstacked': 'stacked', - 'col3dpercentstacked': 'percentStacked', - 'col3dcone': 'standard', - 'col3dconeclustered': 'clustered', - 'col3dconestacked': 'stacked', - 'col3dconepercentstacked': 'percentStacked', - 'col3dpyramid': 'standard', - 'col3dpyramidclustered': 'clustered', - 'col3dpyramidstacked': 'stacked', - 'col3dpyramidpercentstacked': 'percentStacked', - 'col3dcylinder': 'standard', - 'col3dcylinderclustered': 'clustered', - 'col3dcylinderstacked': 'stacked', - 'col3dcylinderpercentstacked': 'percentStacked', - 'line': 'standard'); - return m[t]; - End; - - Function getBarDir(t); - Begin - m := array( - 'bar': 'bar', - 'barstacked': 'bar', - 'barpercentstacked': 'bar', - 'bar3dclustered': 'bar', - 'bar3dstacked': 'bar', - 'bar3dpercentstacked': 'bar', - 'bar3dconeclustered': 'bar', - 'bar3dconestacked': 'bar', - 'bar3dconepercentstacked': 'bar', - 'bar3dpyramidclustered': 'bar', - 'bar3dpyramidstacked': 'bar', - 'bar3dpyramidpercentstacked': 'bar', - 'bar3dcylinderclustered': 'bar', - 'bar3dcylinderstacked': 'bar', - 'bar3dcylinderpercentstacked': 'bar', - 'col': 'col', - 'colstacked': 'col', - 'colpercentstacked': 'col', - 'col3d': 'col', - 'col3dclustered': 'col', - 'col3dstacked': 'col', - 'col3dpercentstacked': 'col', - 'col3dcone': 'col', - 'col3dconestacked': 'col', - 'col3dconeclustered': 'col', - 'col3dconepercentstacked': 'col', - 'col3dpyramid': 'col', - 'col3dpyramidclustered': 'col', - 'col3dpyramidstacked': 'col', - 'col3dpyramidpercentstacked': 'col', - 'col3dcylinder': 'col', - 'col3dcylinderclustered': 'col', - 'col3dcylinderstacked': 'col', - 'col3dcylinderpercentstacked': 'col', - 'line': 'standard'); - return m[t]; - End; - - isWord_; -End; - -Type TPageLine = Class - Function Create(w); - Begin - Width := w; - Init(); - End; - - Function Init(); - Begin - MaxLineHeight := 0; - CurrentLine := 0; - txt_ := ''; - End; - - Function Add(ch, rowHeight, rPr); - Begin - newLine := false; - txt := txt_; - [charW, cnt] := _getCharWidth(ch, rPr); - if CurrentLine + charW > Width then Begin - mh := MaxLineHeight; - Init(); //新行 - newLine := true; - End; - CurrentLine += charW; - if rowHeight > MaxLineHeight then - MaxLineHeight := rowHeight; - return array(newLine, mh, cnt, txt); - End; - - Function _getCharWidth(ch, rPr); - Begin - iChar := ord(ch); - cnt := iChar > 127 ? 2 : 1; - ratio := cnt=1 ? 0.5 : 1; - if ifObj(rPr) then Begin - size := max(rPr.Size, rPr.szCs); - if size=0 then size := 21; - return array(size * 10 * ratio, cnt); - End; - return array(210 * ratio, cnt); //默认五号字 - End; - - Width:integer; - MaxLineHeight:integer; - CurrentLine:integer; - txt_:string; -End; - -//页面设置 -Type TSectPr = Class - Function Create(docx, node); - Begin - docx_ := docx; - PageNo := 1; - LinePos := 0; - PageHash := array(); - ContentArr := array(); - if ifObj(node) then - Init(node); - End; - - Function Init(node); - Begin - pgSz := node.FirstChildElement('w:pgSz'); - if ifObj(pgSz) then Begin - w := pgSz.GetAttribute('w:w'); - h := pgSz.GetAttribute('w:h'); - End; - pgMar := node.FirstChildElement('w:pgMar'); - if ifObj(pgMar) then Begin - left := pgMar.GetAttribute('w:left'); - right := pgMar.GetAttribute('w:right'); - top := pgMar.GetAttribute('w:top'); - bottom := pgMar.GetAttribute('w:bottom'); - End; - PageWidth := Class(TSXml).SafeStrToIntDef(w, 11906)-Class(TSXml).SafeStrToIntDef(left,1800)-Class(TSXml).SafeStrToIntDef(right,1800); - PageHeight := Class(TSXml).SafeStrToIntDef(h, 16838)-Class(TSXml).SafeStrToIntDef(top,1440)-Class(TSXml).SafeStrToIntDef(bottom,1440); - docGrid := node.FirstChildElement('w:docGrid'); - LinePitch := ifObj(docGrid) ? Class(TSXml).SafeStrToIntDef(docGrid.GetAttribute('w:linePitch'), 312) : 312; - PageLine := new TPageLine(PageWidth); - if istable(ContentArr) then Begin //计算当前章节页码 - //w:p;w:tbl - for i:=0 to length(ContentArr)-1 do Begin - [startPage,PageNo,LinePos] := _CalcPage(ContentArr[i]['obj'], PageNo, LinePos);//计算段落、表格、文本框、图片、形状等的页面及大小 - if ContentArr[i]['mark'] >= 0 then - PageHash[ ContentArr[i]['mark'] ] := startPage;//记录页面 - End; - - //下一章节 - PageNo ++; - ContentArr := array(); - LinePos := 0; - End; - End; - - Function Append(p); - Begin - ContentArr[ length(ContentArr) ] := array('obj':p, 'mark':-1); - End; - - Function Mark(ind); - Begin - if istable(ContentArr) then - ContentArr[ length(ContentArr)-1 ]['mark'] := ind; - End; - - Function GetPageNo(ind); - Begin - if ifInt(PageHash[ind]) then - return PageHash[ind]; - return PageNo; - End; - - //计算页面 - Function _CalcPage(obj, page, lpos, more); - Begin - startPage := page; - curPageNo := page; - curLinePos := lpos; - case obj.Name() of - 'w:p': - [startPage, pgNo, line] := _CalcParagraphPage(obj, curPageNo, curLinePos, more); - 'w:tbl': - [startPage, pgNo, line] := _CalcTablePage(obj, curPageNo, curLinePos); - End; - return array(startPage, pgNo, line); - End; - - //段落 - Function _CalcParagraphPage(p, page, lpos, more); - Begin - startPage := page; - curPageNo := page; - curLinePos := lpos; - height := 0;//单位:点(1点=0.3527毫米=1/72英寸) - ETU := 360045;//1cm单位 - defaultLineHeight := LinePitch; //缺省行距 - ParagraphLineHeight := LinePitch; - - defaultPpr := docx_.StyleObject().defaultPpr_;//缺省段落 - defaultRpr := docx_.StyleObject().defaultRpr_;//缺省字体 - pPr := Class(TSXml).ReadPprFormat(p.node_); - //存在段落样式 - StyleId := p.pPr.Value('StyleId'); - if StyleId then Begin - oStyle := docx_.StyleObject().GetStyleById(StyleId); - if ifObj(oStyle) then Begin - stylePpr := oStyle.ReadPprFormat(); //读段落属性(缓存到StyleObject中) - if not ifObj(pPr) then Begin - pPr := stylePpr; - End - else - Class(TSXml).CopyPprFormat(pPr, stylePpr); - //Class(TSXml).CopyPprFormat(pPr, defaultPpr); - - defaultRpr := oStyle.ReadRprFormat(); //读段落字体属性(缓存到StyleObject中) - End; - End - else if ifObj(defaultPpr) then Begin //缺省样式 - if not ifObj(pPr) then Begin - pPr := defaultPpr; - End - else - Class(TSXml).CopyPprFormat(pPr, defaultPpr); - End; - - LineRatio := 1.0; - if ifObj(pPr) then Begin - if pPr.LineSpacingRule = 'exact' and pPr.LineSpacing then //固定行距 - defaultLineHeight := pPr.LineSpacing; - else if pPr.LineSpacing then Begin - LineRatio := pPr.LineSpacing / 240; - //LineRatio := 1.0; - defaultLineHeight := LineRatio * defaultLineHeight; //多倍行距 - End; - ParagraphLineHeight := _GetHeightRatio(pPr, pPr.rPr, LineRatio) * defaultLineHeight; //缺省段落高度(字体) - End; - - //段前 - before := (ifObj(pPr)) ? pPr.SpaceBefore : 0; - after := ifObj(pPr) ? pPr.SpaceAfter : 0; - //段中 - runs := p.GetRuns(); - for i:=0 to length(runs)-1 do Begin - run := runs[i]; - rPr := Class(TSXml).ReadRprFormat(run.node_); - if not ifObj(rPr) then - rPr := defaultRpr; - else - Class(TSXml).CopyRprFormat(rPr, defaultRpr); -//_dumpRpr(rpr); - RunLineHeight := _GetHeightRatio(pPr, rPr, LineRatio) * defaultLineHeight; //缺省段落高度 - pic := run.node_.FirstChildElement('w:drawing/wp:inline/wp:extent');//图片 - if not ifObj(pic) then - pic := run.node_.FirstChildElement('mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:extent');//文本框 - if ifObj(pic) then Begin - cy := Class(TSXml).SafeStrToIntDef(pic.GetAttribute('cy'), LinePitch); - height := cy / ETU / 0.0325; - _addLine(startPage, curPageNo, curLinePos, height, before, linesCnt ? false : true, txt); //加入一行 - linesCnt ++; - continue; - End - - node := run.node_.FirstChildElement(); - while ifObj(node) do Begin - name := node.GetName(); - if name = 'w:br' then Begin - _addLine(startPage, curPageNo, curLinePos, (PageLine.MaxLineHeight ? PageLine.MaxLineHeight : RunLineHeight) + (linesCnt ? 0 : more), 0, linesCnt ? false : true, ''); //加入一行 - PageLine.Init(); - linesCnt ++; - End - else if name = 'w:t' then Begin - txt := node.GetText(); - txtLen := length(txt); - n := 0; - while n < txtLen do Begin - if ifObj(pPr) and PageLine.CurrentLine = 0 then Begin //缩进、悬挂 - PageLine.CurrentLine += _getHanging(linesCnt, pPr); - End; - [newLine, LineHeight, cnt, t] := PageLine.Add(txt[n+1], RunLineHeight, rPr); - PageLine.txt_ += txt[n+1:n+cnt]; - n += cnt; - if newLine then Begin - _addLine(startPage, curPageNo, curLinePos, LineHeight + (linesCnt ? 0 : more), before, linesCnt ? false : true, t); //加入一行 - if ifObj(pPr) then - PageLine.CurrentLine += _getHanging(linesCnt+1, pPr); - linesCnt ++; - End; - End; - End; - node := node.NextElement(); - End; - End; - if linesCnt = 0 and PageLine.CurrentLine = 0 then Begin //空行 - _addLine(startPage, curPageNo, curLinePos, ParagraphLineHeight + more, 0, true, ''); //加入一行 - End - else if PageLine.CurrentLine then Begin - _addLine(startPage, curPageNo, curLinePos, PageLine.MaxLineHeight, before, linesCnt ? false : true, PageLine.txt_); //加入一行 - PageLine.Init(); - linesCnt ++; - End - else Begin - PageLine.Init(); - End; - //段后 -//_dumpPpr(pPr); -//println('Begin Orer=curLinePos={}',curLinePos); - curLinePos += after; -//println('End Orer=curLinePos={}\n\n\n\n',curLinePos); - return array(startPage, curPageNo, curLinePos); - End; - - //表格 - Function _CalcTablePage(tbl, page, lpos); - Begin - startPage := page; - curPageNo := page; - curLinePos := lpos; - topH := Class(TSXml).SafeStrToIntDef(tbl.tblPr.Borders.Top.Value('Val'), 4); //缺省0.5磅,一磅=20点 - bottomH := Class(TSXml).SafeStrToIntDef(tbl.tblPr.Borders.bottom.Value('Val'), 4); //缺省0.5磅 - insideVH := Class(TSXml).SafeStrToIntDef(tbl.tblPr.Borders.insideV.Value('Val'), 4); //缺省0.5磅 - iRow := 0; - trNode := tbl.node_.FirstChildElement('w:tr'); - while ifObj(trNode) do Begin - maxPageNo := curPageNo; - maxLinePos := curLinePos; - tr := new TwTr(nil, 'w:tr'); - tr.RootObj := trNode; - vh := Class(TSXml).SafeStrToIntDef(tr.tblPrEx.Borders.insideV.Value('Val'), insideVH); //行的上边框 - tcNode := trNode.FirstChildElement('w:tc'); - while ifObj(tcNode) do Begin //计算每一个单元格占用页面 - tcPageNo := curPageNo; - tcLinePos := curLinePos; - iCol := 0; - pNode := tcNode.FirstChildElement(); - while ifObj(pNode) do Begin - name := pNode.GetName(); - obj := _getDocObject(pNode, name); - if ifObj(obj) then Begin - [tcStartPage,tcPageNo,tcLinePos] := _CalcPage(ContentArr[i]['obj'], tcPageNo, tcLinePos, iCol = 0 ? (iRow = 0 ? topH * 2.5 : vh * 2.5) : 0); - iCol ++; - End; - pNode := pNode.NextElement(); - End; - if iCol = 0 then Begin //空单元格 - _addLine(tcStartPage, tcPageNo, tcLinePos, (iRow = 0 ? topH * 2.5 : vh * 2.5) + LinePitch, 0, false, ''); - End; - if maxPageNo < tcPageNo then Begin - maxPageNo := tcPageNo; - maxLinePos := tcLinePos; - End - else if maxPageNo = tcPageNo and maxLinePos < tcLinePos then Begin - maxLinePos := tcLinePos; - End; - tcNode := tcNode.NextElement('w:tc'); - End; - iRow++; - trNode := trNode.NextElement('w:tr'); - curPageNo := maxPageNo; - curLinePos := maxLinePos; - End; - //底边框 - _addLine(startPage, curPageNo, curLinePos, bottomH * 2.5, 0, false, ''); - - return array(startPage, curPageNo, curLinePos); - End; - - Function _addLine(startPage, curPageNo, curLinePos, height, before, firstLine, t); - Begin -//println('换行:curLinePos={},height={}, before={}, txt={}',curLinePos, height, before, t); - if curLinePos + height > PageHeight then Begin //放不下,换页 - curPageNo++; - curLinePos := height; -//println('换页:curLinePos={},txt={}',curLinePos, t); - End - else - curLinePos += height + (curLinePos = 0 ? 0 : before); - if firstLine then - startPage := curPageNo; - End; - - Function _GetHeightRatio(pPr, rPr, LineRatio); - Begin - if lineRule = 'exact' then //固定行距 - return 1.0; - if not ifObj(rPr) then - return 1.0; - - return _Font2LineHeight(rPr, LineRatio); //字体大小对应的行距(倍数) - End; - - Function _Font2LineHeight(rPr, LineRatio); - Begin - size := max(ifnil(rPr.Size) ? 0 : rPr.Size, ifnil(rPr.szCs) ? 0 : rPr.szCs); - if size = 0 then size := 21;//缺省五号字 - if rPr.rFont.hint in array('eastAsia', 'zh-CN') or rPr.rFont.eastAsia <> '' then Begin - return ceil(size*10/(LinePitch*LineRatio-200/3)); - End; - - return ceil(size*10/(LinePitch*LineRatio-38)); - End; - - docx_; - PageWidth:integer; - PageHeight:integer; - LinePitch:integer; //行距 - PageNo; - LinePos; - ContentArr; - PageHash; - PageLine; -End; - -//w:body -Type TDocumentBody = Class(DocObject) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - name_ := 'w:body'; - InitNode(node); - End; - - Function InitNode(node); - Begin - node_ := node; - //设置最后一个段落 - _setLastParagraph(); - End; - - Function _setLastParagraph(); - Begin - lastParagraph_ := nil; - if ifObj(node_) then Begin - last := node_.LastChild(); - while ifObj(last) do Begin - name := last.GetName(); - if name in array('w:p', 'w:tbl') then Begin - lastParagraph_ := last; - break; - End; - last := last.Prev(); - End; - End; - End; - - ///返回文档中全部对象列表(TParagraph、TTable等) - Function Parts(); - Begin - return getDocumentObjects(node_, ''); - End; - - ///word文档所有段落 - ///返回:TParagraph对象数组 - Function Paragraphs(); - Begin - parts := getDocumentObjects(node_, 'w:p'); - r := array(); - for i:=0 to length(parts)-1 do Begin - r[i] := new TParagraph(parts[i].node_); - End; - return r; - End; - - ///word最后一个段落 - ///返回:TParagraph对象 - Function LastParagraph(); - Begin - node := node_.LastChildElement('w:p'); - return ifObj(node) ? new TParagraph(node) : nil; - End; - - ///添加新段落 - ///paragraph: TParagraph对象 - ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 - ///[styleId]: int 样式ID - ///返回TParagraph对象 - Function AddParagraph(paragraph, posOpt, styleId); - Begin - if ifString(styleId) and styleId <> '' then Begin - paragraph.Format.StyleId := styleId; - End; - addPart(posOpt, paragraph); - p := new TParagraph(paragraph.node_); - //复制段落字体属性 - p.CopyRunFormat(false, nil); - _set_lastParagraph_(posOpt, p.node_);//设置最后一个段落 - return p; - End; - - ///复制w:p节点内容 - ///paragraphObj: TParagraph对象 - ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 - ///返回TParagraph对象 - Function CopyWp(paragraphObj, posOpt); - Begin - addPart(posOpt, paragraphObj, true); - p := new TParagraph(paragraphObj.node_); - //复制段落字体属性 - p.CopyRunFormat(false, nil); - _set_lastParagraph_(posOpt, p.node_);//设置最后一个段落 - return p; - End; - - ///复制w:tbl节点内容 - ///ttable: TTable对象 - ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 - ///返回TTable对象 - Function CopyWtbl(table, posOpt); - Begin - addPart(posOpt, table, true); - p := new TTable(table.node_); - _set_lastParagraph_(posOpt, p.node_); - return p; - End; - - ///删除指定段落 - ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 第N段;posOpt段落 - ///返回:true - Function DelParagraph(posOpt); - Begin - node := findNode(posOpt, false); - if ifInt(node) then Begin - if node = 0 then - node := node_.FirstChildElement('w:p'); - else if node = -1 then - node := lastParagraph_; - End; - if not ifObj(node) then - return false; - reset_position := false; - if ifObj(TOfficeApi().GetCurrentPosition()) and node.Eq(TOfficeApi().GetCurrentPosition()) then - reset_position := true; - next := node.NextElement('w:p'); - node_.DeleteChild(node); - if not ifObj(next) then - _setLastParagraph(); - if reset_position then - TOfficeApi().Set('CurrentPosition', lastParagraph_); - return true; - End; - - ///添加标题 - ///title: string - ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 - ///level: int 标题级别(0-9) - ///返回TParagraph对象 - Function AddHeading(title, posOpt, styleId); - Begin - paragraph := new TParagraph(); - paragraph.Run.SetText( title ); - if ifObj(document_) then Begin - id := document_.GetBookMarkID(); - paragraph.MarkStart.Name := '_Toc' $ id; - paragraph.MarkStart.ID := id; - paragraph.MarkEnd.ID := id; - End; - return AddParagraph(paragraph, posOpt, styleId); - End; - - ///插入分页符 - ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 - ///返回TParagraph对象 - Function AddBreak(posOpt, tp); - Begin - paragraph := new TParagraph(); - if tp <> '' then - paragraph.Run.Br.Type := tp; - return AddParagraph(paragraph, posOpt); - End; - - //word文档所有内容的文本串数组,包含段落信息 - //返回:array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r)) - Function TextArray();override; - Begin - r := array(); - ps := getDocumentObjects(node_, 'w:p'); - for i:=0 to length(ps)-1 do Begin - pArr := ps[i].TextArray(); - if length(pArr) then Begin - update pArr set ['pIndex'] = i end; - r union= pArr; - End - else Begin - r[ length(r) ] := array('pNode':ps[i].node_, 'pIndex':i, 'rNode':nil, 'rIndex':-1);//空段落 - End; - End; - return r; - End; - - ///word文档所有表格个数 - ///返回:int - Function TablesCount(); - Begin - t := getDocumentObjects(node_, 'w:tbl'); - return length(t); - End; - - ///word文档所有表格 - ///返回:TTable对象数组 - Function Tables(); - Begin - return getDocumentObjects(node_, 'w:tbl'); - End; - - ///word文档指定表格 - ///n: int 第n个表格 - ///返回:TTable对象 - Function GetTable(i); - Begin - t := getDocumentObjects(node_, 'w:tbl'); - if i < 0 or i >= length(t) then return 0; - tbl := new TTable(t[i].node_); - return tbl; - End; - - ///插入数据表 - ///tbl: TTable对象 - ///[posOpt: 段落位置],0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加表格 - Function InsertTable(tbl, posOpt, customCell); - Begin - addPart(posOpt, tbl); - TOfficeApi().Set('CurrentTable', tbl.node_); - tblBorders := class(TSXml).GetNode(tbl.node_, 'w:tblPr/w:tblBorders'); - tblCellMar := class(TSXml).GetNode(tbl.node_, 'w:tblPr/w:tblCellMar'); - if ifObj(tblBorders) or ifObj(tblCellMar) then Begin - borders := ifObj(tblBorders) ? tblBorders.Marshal() : nil; - cellmar := ifObj(tblCellMar) ? tblCellMar.Marshal() : nil; - End; - defaultParagraph := tbl.Paragraph; - if not ifObj(defaultParagraph) then Begin - defaultParagraph := new TParagraph(); - defaultParagraph.pPr.rPr.Lang := 'en-US'; - defaultParagraph.pPr.rPr.eastAsia := 'zh-CN'; - defaultParagraph.Run.rPr.Lang := 'en-US'; - defaultParagraph.Run.rPr.eastAsia := 'zh-CN'; - End; - defaultpPr := defaultParagraph.pPr.Marshal(); - defaultrPr := defaultParagraph.pPr.rPr.Marshal(); - - for i:=0 to length(tbl.Data_)-1 do Begin - trNode := tbl.node_.InsertEndChild('element', 'w:tr'); - trNode.InsertEndChild('element', 'w:trPr'); - multiLine := false; - for j:=0 to tbl.colCount_-1 do Begin - if ifstring(tbl.Data_[i, j]) and Pos('\n', tbl.Data_[i, j]) then - multiLine := true; - //对象太多的话,对象效率奇慢,优化掉(性能可能相差50倍) - if 0 then Begin - tc := new TCell(); - tc.TcPr.Width := tbl.TblGrid.GridCol[j]['obj'].W; - tc.TcPr.Type := 'dxa'; - tc.SetText(tbl.Data_[i, j]); - trNode.InsertEndChild(tc.Marshal()); - continue; - End; - - tcNode := trNode.InsertEndChild('element', 'w:tc'); - if istable(customCell) and ifObj(customCell[i, j, 0]) then - begin - tcNode.InsertEndChild(customCell[i, j, 0].Marshal()); - end - else begin - tcPrNode := tcNode.InsertEndChild('element', 'w:tcPr'); - tcWNode := tcPrNode.InsertEndChild('element', 'w:tcW'); - tcWNode.SetAttribute('w:w', tbl.TblGrid.GridCol[j]['obj'].W); - tcWNode.SetAttribute('w:type', 'dxa'); - end - - if multiLine then Begin - defaultParagraph.node_ := nil; - defaultParagraph.Run.ClearText(); - defaultParagraph.Run.SetText(tbl.Data_[i, j]); - tcNode.InsertEndChild(defaultParagraph.Marshal()); - End - else Begin - pNode := tcNode.InsertEndChild('element', 'w:p'); - if istable(customCell) and ifObj(customCell[i, j, 1]) then - pNode.InsertEndChild(customCell[i, j, 1].Marshal()); - else - pNode.InsertEndChild(defaultpPr); - rNode := pNode.InsertEndChild('element', 'w:r'); - if istable(customCell) and ifObj(customCell[i, j, 2]) then - rNode.InsertEndChild(customCell[i, j, 2].Marshal()); - else - rNode.InsertEndChild(defaultrPr); - tNode := rNode.InsertEndChild('element','w:t', class(TSXml).CurCodePageToUtf8(tbl.Data_[i, j])); - if _preserve(tbl.Data_[i, j]) then - tNode.SetAttribute('xml:space', 'preserve'); - End; -(* - - - - - - - - - - - - - - - Index - - - -*) - End; - //if ifObj(tblCellMar) then Begin - // c := class(TSXml).GetNode(trNode, 'w:tblPrEx/w:tblCellMar', 'first'); - // class(TSXml).UpdateNode(c, cellmar[0]['attributes'], cellmar[0]['children']); - //End; - //if ifObj(tblBorders) then Begin - // b := class(TSXml).GetNode(trNode, 'w:tblPrEx/w:tblBorders', 'first'); - // class(TSXml).UpdateNode(b, borders[0]['attributes'], borders[0]['children']); - //End; - End; - node_.Parent().SetAttribute('mc:Ignorable', 'w14 w15 wp14'); - node_.Parent().SetAttribute('xmlns:w15', 'http://schemas.microsoft.com/office/word/2012/wordml'); - _set_lastParagraph_(posOpt, tbl.node_); - - p := new TTable(tbl.node_); - return p; - End; - - ///插入图片 - ///picture: TPicture对象 - ///[posOpt: 段落位置],0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加表格 - ///[docx]: 可选参数,TSDocxFile对象,在TTextBox、TCell中调用需要传入文档对象 - Function AddPicture(picture, posOpt, docx); - Begin - if ifObj(docx) then Begin - zipfile_ := docx.Zip(); - picture.Run.Drawing.WInline.ID := docx.GetDocPrId(); - End; - if not ifBinary(picture.Image) or length(picture.Image)=0 then - raise 'Invalid Image Data.'; - if not ifObj(zipfile_) then - raise 'no support'; - image := new TSImage(picture.Image); - xml := zipfile_.Get('word/_rels/document.xml.rels'); - files := sselect ['FileName'] from zipfile_.Files() where AnsiStartsText('word/media/image', ['FileName']) end; - for i:=0 to length(files)-1 do Begin - if zipfile_.Diff(files[i], picture.Image) = 0 then Begin - prefix := ReplaceStr(files[i], 'word/', ''); - [maxRid, imageFile, rid] := class(TSXml).FindRelationshipRid(xml, prefix); - End; - End; - if rid = 0 then Begin - imageCnt := length(files) + 1; - imageFile := 'media/image' $ imageCnt $ '.' $ image.ExtFileName; - [rid, target] := class(TSXml).FindRelationshipRid(xml, ''); - rid ++; - class(TSXml).AddRelationshipRid(xml, imageFile, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'rId' $ rid); - zipfile_.Add('word/' + imageFile, picture.Image); - contentXml := zipfile_.Get('[Content_Types].xml'); - class(TSXml).AddDefaultContentType(contentXml, image.ExtFileName, 'image/' $ image.ExtFileName); - End; - [cx, cy] := picture.ScaledDimensions(image);//extent 元素通过其属性指定此对象的高度和宽度为 [cx,cy] ETU (英语公制单位) - //println('cx={},cy={},w={},h={}',cx,cy,image.px_width,image.px_height); - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.BlipFill.blip.Embed := 'rId' $ rid; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.BlipFill.Stretch.FillRect := 1; - picId := getPictureMaxId() + 1; - picture.Run.Drawing.WInline.Name := '图片 ' $ picId; - picture.Run.Drawing.WInline.Descr := class(TSXml).CurCodePageToUtf8(picture.Descr); - picture.Run.Drawing.WInline.cNvGraphicFramePr.xmlns := 'http://schemas.openxmlformats.org/drawingml/2006/main'; - picture.Run.Drawing.WInline.cNvGraphicFramePr.noChangeAspect := 1; - picture.Run.Drawing.WInline.Graphic.xmlns := 'http://schemas.openxmlformats.org/drawingml/2006/main'; - picture.Run.Drawing.WInline.Graphic.GraphicData.uri := 'http://schemas.openxmlformats.org/drawingml/2006/picture'; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.xmlns := 'http://schemas.openxmlformats.org/drawingml/2006/picture'; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.CNvPr.ID := picture.Run.Drawing.WInline.ID; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.CNvPr.Name := picture.Run.Drawing.WInline.Name; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.CNvPr.Descr := picture.Run.Drawing.WInline.Descr; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.cNvPicPr.NodeName := 'pic:cNvPicPr'; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.cNvPicPr.PicLocks := 1; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.PrstGeom.prst := 'rect'; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.PrstGeom.avLst := true; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Off.X := 0; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Off.Y := 0; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Ext.CX := cx; - picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Ext.CY := cy; - picture.Run.Drawing.WInline.distR := 114300; - picture.Run.Drawing.WInline.distL := 114300; - picture.Run.Drawing.WInline.distB := 0; - picture.Run.Drawing.WInline.distT := 0; - picture.Run.Drawing.WInline.cy := cy; - picture.Run.Drawing.WInline.cx := cx; - //picture.Run.Drawing.WInline.r := 0; - //picture.Run.Drawing.WInline.b := 5080; - //picture.Run.Drawing.WInline.t := 0; - //picture.Run.Drawing.WInline.l := 0; - addPart(posOpt, picture); - - p := new TPicture(picture.node_); - _set_lastParagraph_(posOpt, picture.node_); - picture.node_.InsertFirstChild('element', 'w:pPr'); - TOfficeApi().Set('CurrentShape', picture.node_); - return p; - End; - - ///文档中全部的批注信息 - ///返回:TDocComments对象 - Function Comments();overload; - Begin - t := array(); - [startCnt, endCnt, tCnt, index] := array(0, 0, 0, 0); - p := node_.FirstChildElement('w:p'); - while ifObj(p) do Begin - child := p.FirstChildElement(); - rIndex := 0; - while ifObj(child) do Begin - id := -1; - name := child.GetName(); - if name = 'w:commentRangeStart' then Begin - startCnt ++; - id := strtoint(child.GetAttribute('w:id')); - t[ tCnt++ ] := array('pNode':p, 'rNode':child, 'Name':name, 'Start':startCnt, 'End':endCnt, 'ID':id, 'pIndex':index); - End - else if name = 'w:commentRangeEnd' then Begin - endCnt ++; - id := strtoint(child.GetAttribute('w:id')); - t[ tCnt++ ] := array('pNode':p, 'rNode':child, 'Name':name, 'Start':startCnt, 'End':endCnt, 'ID':id, 'pIndex':index); - End - else if name = 'w:r' and startCnt > endCnt then Begin - t[ tCnt++ ] := array('pNode':p, 'rNode':child, 'Name':name, 'Start':startCnt, 'End':endCnt, 'ID':-1, 'pIndex':index); - End; - child := child.NextElement(); - End; - index ++; - p := p.NextElement('w:p'); - End; - return new TDocComments(t); - End; - - //返回TDocSection对象集合 - Function Sections();overload; - Begin - index := 0; - r := array(); - node := node_.FirstChildElement(); - while ifObj(node) do Begin - name := node.GetName(); - if name = 'w:sectPr' then Begin - section := new TDocSection(node, index++, zipfile_); - r[length(r)] := section; - End - else if name = 'w:p' then Begin - child := class(TSXml).GetNode(node, 'w:pPr/w:sectPr', false); - if ifObj(child) then Begin - section := new TDocSection(node, index++, zipfile_); - r[length(r)] := section; - End; - End; - node := node.NextElement(); - End; - return r; - End; - - //index:integer 章节索引 - //返回:指定TDocSection对象 - Function Sections(index);overload; - Begin - if index < 0 then Begin //返回文档最后一个章节(缺省章节) - node := node_.LastChild('w:sectPr'); - if ifObj(node) then - return new TDocSection(node, -1, zipfile_); - return nil; - End; - arr := Sections(); - if length(arr) >= index then - return nil; - return arr[index]; - End; - - //添加章节 - //section:TDocSection对象 - //posOpt: 位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加章节 - //返回:TDocSection对象 - Function AddSection(section, posOpt);overload; - Begin - section.zipfile_ := zipfile_; - p := new TParagraph(); - p.pPr.NewChildNode( array("field":"", "name":"w:sectPr", "obj":section, "attrEx":"", "nodeType":"") ); - p := AddParagraph(p, posOpt, '');//段落对象 - return new TDocSection(p.node_.FirstChildElement('w:pPr').FirstChildElement('w:sectPr'), -2, zipfile_); - End; - - Function ExecInnerTSL(docx); - Begin - //表格 - t := array(); - tslFuncCount := 0; - errArr := array(); - tArr := Tables(); - for i:=0 to length(tArr)-1 do Begin - col := tArr[i].Cols(); - row := tArr[i].Rows(); - for r:= 1 to row do Begin - for c:=1 to col do Begin - cell := tArr[i].Cell(r, c); - [err, cnt, err] := cell.ExecInnerTSL(docx);//递归 - tslFuncCount += cnt; - errArr union= err; - End; - End; - End; - - //文本框 - ps := Paragraphs(); - for i:=0 to length(ps)-1 do Begin - boxs := ps[i].TextBoxs(); - for j:=0 to length(boxs)-1 do Begin - [err, cnt, err] := boxs[j].ExecInnerTSL(docx);//递归 - if cnt then - boxs[j].Apply(); - tslFuncCount += cnt; - errArr union= err; - End; - End; - - //页脚、页眉 - sArr := Sections(); - tpArr := array('default','even','first'); - for i:=0 to length(sArr)-1 do Begin - for k, name in tpArr do Begin - h := sArr[i].Header(name); - if ifObj(h) then Begin - [err, cnt, err] := h.ExecInnerTSL(docx);//递归 - tslFuncCount += cnt; - errArr union= err; - End; - - f := sArr[i].Footer(name); - if ifObj(f) then Begin - [err, cnt, err] := f.ExecInnerTSL(docx);//递归 - tslFuncCount += cnt; - errArr union= err; - End; - End; - End; - - [err, cnt, err] := ExecInnerTSLImpl(docx); - tslFuncCount += cnt; - errArr union= err; - return array(length(errArr), tslFuncCount, errArr); - End; - - Function RunTslCode(code, err); - Begin - try - //println('run code=[{}]', code); - if code <> '' then - eval(&code); - except - err := ExceptObject.ErrInfo; - return false; - End; - return true; - End; - - Function ExecInnerTSLImpl(docx); - Begin - tslFuncCount := 0; - errArr := array(); - tslArr := array(); - tArr := TextArray(); - flag := ''; - code := nil; - begParagraphIndex := -1; - begPos := 0; - begTxtLen := 0; - while i < length(tArr) do Begin - txt := ''; - iStep := 1; - if ifObj(tArr[i]['rNode']) then Begin - run := new TRun(tArr[i]['rNode']); - txt := run.Text(); - if class(TSXml).IsUtf8() then - txt := UTF8ToAnsi(txt); - End; - k := 1; - wz := 1; - txtLen := length(txt); - while k <= txtLen do Begin - c := txt[k]; - case flag of - '': - if c = '[' then Begin - flag := '['; - begParagraphIndex := i; - begPos := wz; - begTxtLen := txtLen; - End; - '[': - if c = 'T' or c = 't' then - flag := '[T'; - else - flag := ''; - '[T': - if c = 'S' or c = 's' then - flag := '[TS'; - else - flag := ''; - '[TS': - if c = 'L' or c = 'l' then - flag := '[TSL'; - else - flag := ''; - '[TSL': - if c = ']' then Begin - flag := '[TSL]'; - tslArr := tArr[begParagraphIndex:i,:]; - code := ''; - k++; - wz++; - continue; - End - else - flag := ''; - '[TSL]': - if c = '[' then Begin - flag := '[TSL]['; - endPos := 0; - End - '[TSL][': - if c = '/' then - flag := '[TSL][/'; - else - flag := '[TSL]'; - '[TSL][/': - if c = 'T' or c='t' then - flag := '[TSL][/T'; - else - flag := '[TSL]'; - '[TSL][/T': - if c = 'S' or c='s' then - flag := '[TSL][/TS'; - else - flag := '[TSL]'; - '[TSL][/TS': - if c = 'L' or c='l' then - flag := '[TSL][/TSL'; - else - flag := '[TSL]'; - '[TSL][/TSL': - if c = ']' then Begin - tslBegParagraphNode := tslArr[0]['pNode']; - tslEndParagraphNode := tArr[i]['pNode']; - ind := length(tslArr) - 1; - if tslArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tslArr[ind]['rIndex'] <> tArr[i]['rIndex'] then Begin - ind ++; - tslArr[ind] := tArr[i]; - End; - if begPos > 1 then Begin //函数前分割为新的w:r - prevRun := run._duplicate_r(tArr[begParagraphIndex]['rNode']); - run._adjust_r(tArr[begParagraphIndex]['rNode'], 0, begPos - 1); - tslArr[0]['rNode'] := prevRun; - End; - if k < txtLen then Begin //函数后面分割为新的w:r - oldNode := run.node_; - if begParagraphIndex = i and begPos > 1 then - oldNode := prevRun; - tArr[i]['rNode'] := run._duplicate_r(oldNode); - run._adjust_r(tArr[i]['rNode'], wz, txtLen); - iStep := 0; - End; - curRunNode := tslArr[0]['rNode']; - curRun := new TRun(curRunNode); - curRun.ClearText(); - rmvPara := array(); - for m := 1 to length(tslArr) - 1 do Begin - if ifObj(tslArr[m]['rNode']) then Begin - tslArr[m]['pNode'].DeleteChild(tslArr[m]['rNode']); - hasrNode := tslArr[m]['pNode'].FirstChildElement('w:r'); - if not ifObj(hasrNode) then - rmvPara[ tslArr[m]['pIndex'] ] := tslArr[m]['pNode']; - End - else - rmvPara[ tslArr[m]['pIndex'] ] := tslArr[m]['pNode']; - End; - for index, pNode in rmvPara do Begin - pNode.Parent().DeleteChild(pNode); - End; - //run inner tsl - code := leftstr(code, lengthW(code) - 5 - endPos); - CodePage := TOfficeApi().Get('CodePage'); - TOfficeApi().Set('Docx', docx); - TOfficeApi().Set('CurrentParagraph', tslBegParagraphNode); - TOfficeApi().Set('CurrentPosition', tslBegParagraphNode); - TOfficeApi().Set('CurrentRun', curRunNode); - TOfficeApi().Set('CodePage', 'gbk'); - if not RunTslCode(code, err) then Begin - echo 'run code=',code,',err=', err, '\n'; - errArr[ length(errArr) ] := array('code':code, 'err':err); - End; - tslFuncCount ++; - tNode := curRun.node_.FirstChildElement('w:t'); - if not ifObj(tNode) then Begin //没有在外部插入文字 - tslBegParagraphNode.DeleteChild(curRunNode); - //兼容WordTemplate函数,不删除空段落(TSL脚本段落) - //hasrNode := tslBegParagraphNode.FirstChildElement('w:r'); - //if not ifObj(hasrNode) then Begin//删除空段落 - // tslBegParagraphNode.Parent().DeleteChild(tslBegParagraphNode); - // tslBegParagraphNode := nil; - //End; - End; - //段落炸裂 - curPosotion := TOfficeApi().Get('CurrentPosition'); - if i+iStep < length(tArr) and tArr[i+iStep]['pNode'] = tslEndParagraphNode and tslBegParagraphNode <> curPosotion then Begin - data := tslEndParagraphNode.Marshal(); - NewParagraphNode := tslEndParagraphNode.Parent().InsertAfterChild(curPosotion, data[0]);//复制段落 - rmvArr := array(); - cnt := 0; - curLine := 0; - prevRNode := tArr[i+iStep]['rNode'].PrevElement('w:r'); - while ifObj(prevRNode) do Begin - curLine ++; - prevRNode := prevRNode.PrevElement('w:r'); - End; - rmvN := 0; - nextRNode := tArr[i+iStep]['rNode']; - while ifObj(nextRNode) do Begin - rmvArr[rmvN++] := nextRNode; - nextRNode := nextRNode.NextElement('w:r'); - End; - rNode := NewParagraphNode.FirstChildElement('w:r'); - nI := 0; - rIndex := 0; - while ifObj(rNode) do Begin - cnt ++; - if cnt <= curLine then Begin - rmvArr[rmvN++] := rNode; - End - else Begin - tArr[i+iStep+nI]['pNode'] := NewParagraphNode; - tArr[i+iStep+nI]['rNode'] := rNode; - tArr[i+iStep+nI]['rIndex'] := rIndex++; - nr := new TRun(tArr[i+iStep+nI]['rNode']); - nI ++; - End; - rNode := rNode.NextElement('w:r'); - End; - //删除重复的run - for rmvN := 0 to length(rmvArr)-1 do begin - rmvArr[rmvN].Parent().DeleteChild(rmvArr[rmvN]); - End; - End; - TOfficeApi().Set('CodePage', CodePage); - - flag := ''; - code := nil; - tslArr := array(); - break; - End - else - flag := '[TSL]'; - End; - if Ord(c) > 127 then Begin - if ifstring(code) then - code += txt[k:k+1]; - k ++; - End - else if ifstring(code) then - code += c; - k ++; - wz ++; - End; - if length(tslArr) then Begin - //println('pIndex={},txt={},i={}',tArr[i]['pIndex'], txt, i); - if i and i < length(tArr) and tArr[i]['pIndex'] <> tArr[i+1]['pIndex'] then Begin - code += '\n'; - endPos ++; - End; - ind := length(tslArr) - 1; - if tslArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tslArr[ind]['rIndex'] <> tArr[i]['rIndex'] then - tslArr[ind + 1] := tArr[i]; - End; - i += iStep; - End; - return array(length(errArr), tslFuncCount, errArr); - End; - - Function ExecTsTag(docx, tagName, tagObj); - Begin - //表格 - t := array(); - tslTagCount := 0; - errArr := array(); - tArr := Tables(); - for i:=0 to length(tArr)-1 do Begin - col := tArr[i].Cols(); - row := tArr[i].Rows(); - for r:= 1 to row do Begin - for c:=1 to col do Begin - cell := tArr[i].Cell(r, c); - [err, cnt, err] := cell.ExecTsTag(docx, tagName, tagObj);//递归 - tslTagCount += cnt; - errArr union= err; - End; - End; - End; - - //文本框 - ps := Paragraphs(); - for i:=0 to length(ps)-1 do Begin - boxs := ps[i].TextBoxs(); - for j:=0 to length(boxs)-1 do Begin - [err, cnt, err] := boxs[j].ExecTsTag(docx, tagName, tagObj);//递归 - if cnt then - boxs[j].Apply(); - tslTagCount += cnt; - errArr union= err; - End; - End; - - //页脚、页眉 - sArr := Sections(); - tpArr := array('default','even','first'); - for i:=0 to length(sArr)-1 do Begin - for k, name in tpArr do Begin - h := sArr[i].Header(name); - if ifObj(h) then Begin - [err, cnt, err] := h.ExecTsTag(docx, tagName, tagObj);//递归 - tslTagCount += cnt; - errArr union= err; - End; - - f := sArr[i].Footer(name); - if ifObj(f) then Begin - [err, cnt, err] := f.ExecTsTag(docx, tagName, tagObj);//递归 - tslTagCount += cnt; - errArr union= err; - End; - End; - End; - - [err, cnt, err] := ExecTsTagImpl(docx, tagName, tagObj); - tslTagCount += cnt; - errArr union= err; - return array(length(errArr), tslTagCount, errArr); - End; - - Function ExecTsTagImpl(docx, tagName, tagObj); - Begin - tslTagCount := 0; - errArr := array(); - tagArr := array(); - tArr := TextArray(); - tagAttribute := ''; - tagStr := ''; - tagStatus := '';//array('','head', 'attribute', 'tail'); - tagHead := '[' + tagName; - tagTail := '[/' + tagName; - tmp := array(); - while i < length(tArr) do Begin - txt := ''; - iStep := 1; - if ifObj(tArr[i]['rNode']) then Begin - run := new TRun(tArr[i]['rNode']); - txt := run.Text(); - if class(TSXml).IsUtf8() then - txt := UTF8ToAnsi(txt); - End; - k := 1; - wz := 1; - txtLen := length(txt); - while k <= txtLen do Begin - c := txt[k]; - if c = ']' and (tagStatus = 'head' or tagStatus = 'attribute') and tagStr = tagHead then Begin //TAG头结束标志 - tagStr := ''; - tagArr := tArr[tmp['head-begin-paragraph']:i,:]; - wz++; - tagStatus := 'tail'; - tmp['head-end-paragraph'] := i; - tmp['head-end-pos'] := k++; - tmp['head-end-wz'] := wz; - tmp['head-end-txtlen'] := txtLen; - continue; - End; - case tagStatus of - '': - if c = '[' then Begin - tagStr := '['; - tmp['head-begin-paragraph'] := i; - tmp['head-begin-pos'] := k; - tmp['head-begin-wz'] := wz; - tmp['head-begin-txtlen'] := txtLen; - tagStatus := 'head'; - tagAttribute := ''; - End; - 'head': - if c = ' ' and tagStr = tagHead then Begin //找到TAG属性 - tagStatus := 'attribute'; - End - else if length(tagStr) < length(tagHead) and lowercase(c) = lowercase(tagHead[ length(tagStr) + 1 ]) then Begin - tagStr += tagHead[ length(tagStr) + 1 ]; - End - else //继续寻找TAG开始标志 - tagStatus := ''; - 'attribute': - tagAttribute += c; - 'tail': - if c=']' and tagStr = tagTail then Begin //查找到完整标签 - ind := length(tagArr) - 1; - if tagArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tagArr[ind]['rIndex'] <> tArr[i]['rIndex'] then Begin - ind ++; - tagArr[ind] := tArr[i]; - End; - - //[/tag]后 - if k < txtLen then Begin //后面分割为新的w:r - tArr[i]['rNode'] := run._duplicate_r(tArr[i]['rNode']); - run._adjust_r(tArr[i]['rNode'], wz, txtLen); - iStep := 0; - End; - //前[/tag] - tagInd := length(tagArr) - i + tmp['tail-begin-paragraph'] - 1; - if tmp['tail-begin-pos'] > 1 then Begin - nNode := run._duplicate_r(tagArr[tagInd]['rNode']); - run._adjust_r(tagArr[tagInd]['rNode'], 0, tmp['tail-begin-wz'] - 1); - tagArr[tagInd]['pNode'].DeleteChild(nNode); - tmp['tag-end'] := tagInd; - End - else if tmp['tail-begin-pos'] = 1 then Begin - tmp['tag-end'] := tagInd - 1; - End; - - //[tag]后 - firstNode := tagArr[0]['rNode']; - tagInd := length(tagArr) - i + tmp['head-end-paragraph'] - 1; - if tmp['head-end-pos'] < tmp['head-end-txtlen'] then Begin - oldNode := tagArr[tagInd]['rNode']; - tagArr[tagInd]['rNode'] := run._duplicate_r(oldNode); - run._adjust_r(tagArr[tagInd]['rNode'], tmp['head-end-wz'] - 1, tmp['head-end-txtlen']); - tmp['tag-beg'] := tagInd; - if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then - tagArr[tagInd]['pNode'].DeleteChild(oldNode); - End - else if tmp['head-end-pos'] = tmp['head-end-txtlen'] and tagInd then Begin - tmp['tag-beg'] := tagInd + 1; - End; - //前[tag] - if tmp['head-begin-pos'] > 1 then Begin - run._adjust_r(firstNode, 0, tmp['head-begin-wz'] - 1); - if firstNode = tagArr[0]['rNode'] then - tagArr[0]['rNode'] := nil; - End - else if tagInd=0 and tmp['tag-beg']=0 then - tagArr[0]['pNode'].DeleteChild(firstNode); - - //执行TAG逻辑 - r := array(); - for nI := 0 to length(tagArr)-1 do Begin - if not ifObj(tagArr[nI]['rNode']) then continue; - if nI >= tmp['tag-beg'] and nI <= tmp['tag-end'] then - r[length(r)] := tagArr[nI];//标签中间文字内容 - else Begin //删除标签 - tagArr[nI]['pNode'].DeleteChild(tagArr[nI]['rNode']); - node := tagArr[nI]['pNode'].FirstChildElement('w:r'); - if not ifObj(node) then Begin - tagArr[nI]['pNode'].Parent().DeleteChild(tagArr[nI]['pNode']); - End; - End; - End; - tagObj.Init(tagName, tagAttribute, r); - tagObj.Apply(); - tslTagCount++; - - tagStatus := ''; - tagArr := array(); - break; - End - else if length(tagStr) < length(tagTail) and lowercase(c) = lowercase(tagTail[ length(tagStr) + 1 ]) then Begin - tagStr += tagTail[ length(tagStr) + 1 ]; - if tagStr = '[' then Begin - tmp['tail-begin-paragraph'] := i; - tmp['tail-begin-pos'] := k; - tmp['tail-begin-wz'] := wz; - tmp['tail-begin-txtlen'] := txtLen; - End; - End - else //继续寻找TAG结束标志 - tagStr := ''; - End; - if Ord(c) > 127 then Begin - k ++; - End - k ++; - wz ++; - End; - if length(tagArr) then Begin - if i and i < length(tArr) and tArr[i]['pIndex'] <> tArr[i+1]['pIndex'] then Begin - endPos ++; - End; - ind := length(tagArr) - 1; - if tagArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tagArr[ind]['rIndex'] <> tArr[i]['rIndex'] then - tagArr[ind + 1] := tArr[i]; - End; - i += iStep; - End; - return array(length(errArr), tslTagCount, errArr); - End; - - Function GetHeadingListImpl(docx, posOpt, UpperHeadingLevel, LowerHeadingLevel, numIds); - Begin - r := array(); - if ifObj(posOpt) then - pNode := posOpt.NextElement(); - else - pNode := node_.FirstChildElement(); - while ifObj(pNode) do Begin - name := pNode.GetName(); - if name = 'w:p' and not ifObj(pNode.FirstChildElement('w:sectPr')) then - begin - pStyle := class(TSXml).GetNode(pNode, "w:pPr/w:pStyle"); - level := nil; - if pStyle then - begin - styleId := pStyle.GetAttribute('w:val'); - if styleId <> '' and (obj := docx.StyleObject().GetStyleById(styleId)) and ifObj(obj) then - begin - level := getHeadingLevel(docx, obj); - end - end - else begin - level := class(TSXml).GetNode(pNode, "w:pPr/w:outlineLvl"); - if ifObj(level) then level := level.GetAttribute("w:val"); - end - if not ifnil(level) then - begin - iLevel := Class(TSXml).SafeStrToIntDef(level, -1); - if iLevel+1 >= UpperHeadingLevel and iLevel+1 <= LowerHeadingLevel then Begin - //统计数字项目编号 - p := new TParagraph(pNode); - text := p.Text(); - if text = "" then - begin - pNode := pNode.NextElement(); - continue; - end - numArr := array(); - numId := getNumPr('numId', docx, p); - ilvl := getNumPr('Level', docx, p); - if not ilvl then ilvl := 0; - if ifarray(numIds) then Begin - if ilvl >= 0 and ilvl < 10 then Begin - if not istable(numIds[numId]) then - numIds[numId] := array(0,0,0,0,0,0,0,0,0,0); - prev := numIds[numId, ilvl]; - if prev then Begin - for i:=ilvl+1 to 9 do - numIds[numId, i] := 0; - End; - numIds[numId, ilvl]++; - numArr := numIds[numId]; - End; - End; - r[ind]['Level'] := strtoint(level); - r[ind]['Paragraph'] := p; - r[ind]['Text'] := text; - r[ind]['numId'] := ifnumber(numId) ? integer(numId) : 0; //数字项目编号 - r[ind]['ilvl'] := ilvl; //级别 - r[ind]['numArr'] := numArr; //累加数字编码 - ind++; - End; - end - End - else if false and ifarray(numIds) and name = 'w:tbl' then Begin - tbl := TOfficeObj('TTable'); - tbl.Init(pNode); - rows := tbl.Rows(); - cols := tbl.Cols(); - for i:=1 to rows do Begin - for j:=1 to cols do Begin - cell := tbl.Cell(i, j); - if cell then [a, b] := cell.GetHeadingListImpl(docx, nil, UpperHeadingLevel, LowerHeadingLevel, numIds);//表格内递归查找,统计数字项目编号,但不显示在大纲中 - End; - End; - End; - pNode := pNode.NextElement(); - End; - - return r; - End; - - Function getNumPr(field, docx, p); - Begin - value := p.Format.NumPr.Value(field); - if value then return value; - styleId := p.Format.Value('StyleId', 1); - return getFieldByStyle(field, docx, docx.StyleObject().GetStyleById(styleid)); - End; - - Function getFieldByStyle(field, docx, obj); - Begin - if not ifObj(obj) then return ''; - numId := obj.pPr.numPr.Value(field); - if numId = '' then - begin - id := o.Value('BasedOn'); - return getNumIdByStyle(docx, docx.StyleObject().GetStyleById(id)); - end - return numId; - End; - - Function getHeadingLevel(docx, obj); - Begin - if not ifObj(obj) then return ''; - o := obj; - level := obj.HeadingLevel(); - if level = '' then - begin - id := o.Value('BasedOn'); - return getHeadingLevel(docx, docx.StyleObject().GetStyleById(id)); - end - return level; - End; - - - Function getPictureMaxId(); - Begin - id := 0; - pNode := node_.FirstChildElement('w:p'); - while ifObj(pNode) do Begin - rNode := pNode.FirstChildElement('w:r'); - while ifObj(rNode) do Begin - node := class(TSXml).GetNode(rNode, 'w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blibFill/a:blib'); - if ifObj(node) then Begin - v := node.GetAttribute('r:embed'); - if v <> '' then Begin - iVal := strtoint(v); - if iVal > id then id := iVal; - End; - End; - rNode := rNode.NextElement('w:r'); - End; - pNode := pNode.NextElement('w:p'); - End; - return id; - End; - - Function addPart(posOpt, o, flag); - Begin - node := posOpt; - if ifObj(posOpt) and not (posOpt is Class(XmlNode)) then - node := posOpt.Node(); - node := findNode(node, true); - if flag then nodeArr := o.node_.Marshal()[0]; - else nodeArr := o.Marshal(); - if ifObj(node) then Begin - o.node_ := node_.InsertAfterChild(node, nodeArr); //XmlNode节点对象或DocObject对象 - End - else if node = 0 then Begin - o.node_ := node_.InsertFirstChild(nodeArr); - End - else if node < 0 then Begin - o.node_ := node_.InsertEndChild(nodeArr); - End - else Begin - raise 'Invalid input param.'; - End; - TOfficeApi().Set('CurrentPosition', o.node_); - End; - - Function findNode(posOpt, b); - Begin - if not ifObj(lastParagraph_) then - return 0; - if ifObj(posOpt) then - return posOpt; - if b and posOpt = 0 then Begin - return 0; - End; - if posOpt < 0 then - return lastParagraph_; - - if ifInt(posOpt) then Begin - node := node_.FirstChildElement(); - ind := 0; - while ifObj(node) do Begin - name := node.GetName(); - if name = 'w:p' or name = 'w:tbl' then - ind ++; - if ind = posOpt + ifthen(b, 0, 1) then - return node; - node := node.NextElement(); - End; - End; - if b then - return lastParagraph_; - return 0; - End; - - Function getText(t); - Begin - if not ifstring(t) then return '' $ t; - return t; - txt := ReplaceStr(t, '\t', ''); - txt := ReplaceStr(txt, '\r\n', ''); - txt := ReplaceStr(txt, '\n', ''); - return txt; - End; - - Function _set_lastParagraph_(posOpt, node); - Begin - if not ifObj(lastParagraph_) then - lastParagraph_ := node; - else if ifInt(posOpt) and posOpt = -1 then - lastParagraph_ := node; - else if ifObj(posOpt) then Begin - posNode := posOpt; - if not (posOpt is Class(XmlNode)) then - posNode := posOpt.Node(); - if lastParagraph_.Eq(posNode) then Begin - _setLastParagraph(); - End; - End; - End; - - zipfile_; - lastParagraph_; - document_; -End; - -Type TDocHeaderFooter = Class(TDocumentBody) - Function Create(rid, obj, name); - Begin - rID_ := rid; - xmlObj_ := obj; - node := xmlObj_.FirstChildElement(name); - Index := -1; - Class(TDocumentBody).Create(node); - name_ := name; - End; - - ///添加页码 - ///fmt:string,页码格式(eg:"第 {0} 页,共 {1} 页") - ///font:字体格式 - Function AddPageNumber(fmt, font); - Begin - r := array(); - fmtLen := length(fmt); - txt := ''; - while i < fmtLen do Begin - if fmt[i+1] = '{' and i + 2 <= fmtLen and fmt[i+3] = '}' then Begin - if txt <> '' then - r[ cnt++ ] := txt; - r[ cnt++ ] := fmt[i+1:i+3]; - txt := ''; - i += 3; - End - else Begin - txt += fmt[i+1]; - i ++; - End; - End; - if txt <> '' then - r[ cnt++ ] := txt; - p := TOfficeObj('TParagraph'); - class(TSXml).CopyRprFormat(p.pPr.rPr, font); - for i:=0 to length(r)-1 do Begin - run := p.AddRun(); - if r[i] = '{0}' then Begin //页码 - run.fldCharType := 'begin'; - class(TSXml).CopyRprFormat(run.rPr, font); - PageNo := p.AddRun(); - PageNo.InstrText := ' PAGE \\* MERGEFORMAT '; - PageNo.InstrTextSpace := 'preserve'; - class(TSXml).CopyRprFormat(PageNo.rPr, font); - run := p.AddRun(); - run.fldCharType := 'end'; - class(TSXml).CopyRprFormat(run.rPr, font); - End - else if r[i] = '{1}' then Begin //总页数 - run.fldCharType := 'begin'; - class(TSXml).CopyRprFormat(run.rPr, font); - TotalPageNo := p.AddRun(); - TotalPageNo.InstrText := ' NUMPAGES \\* MERGEFORMAT '; - TotalPageNo.InstrTextSpace := 'preserve'; - class(TSXml).CopyRprFormat(TotalPageNo.rPr, font); - run := p.AddRun(); - run.fldCharType := 'end'; - class(TSXml).CopyRprFormat(run.rPr, font); - End - else Begin - run.SetText( r[i] ); - class(TSXml).CopyRprFormat(Run.rPr, font); - End; - End; - return AddParagraph(p, -1, nil); - End; - - rId_:integer; - xmlFileName_:string; - root_; - xmlObj_; -End; - -Type TCols = Class(TColsImpl) - Function AddCol(); - Begin - o := new TCol(); - NewChildNode( array("field":"", "name":"w:col", "obj":o, "attrEx":"", "nodeType":"") ); - return o; - End; - -End; - -Type TDocSection = Class(DocObject, TDocSectionImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Create(node, -1, nil); - End; - - Function Create(node, index, z);overload; - Begin - Index_ := index; - name_ := 'w:sectPr'; - node_ := node; - zipfile_ := z; - Class(TDocSectionImpl).Create(nil, name_); - InitRootNode(node); - End; - - ///返回指定页眉 - ///type:页眉类型,(default、even、first) - ///default, Header for odd pages or all if no even header. - ///first, Header for first page of section. - ///even, Header for even pages of recto/verso section. - Function Header(type); - Begin - return _getHeaderFooter('w:headerReference', type); - End; - - ///返回指定页脚 - ///type:页眉类型,(default、even、first) - ///default, Header for odd pages or all if no even header. - ///first, Header for first page of section. - ///even, Header for even pages of recto/verso section. - Function Footer(type); - Begin - return _getHeaderFooter('w:footerReference', type); - End; - - ///添加页眉 - ///type:页眉类型,(default、even、first) - ///default, Header for odd pages or all if no even header. - ///first, Header for first page of section. - ///even, Header for even pages of recto/verso section. - Function AddHeader(type); - Begin - return _AddHeaderFooter('header', (ifNil(type) or type = '') ? 'default' : type); - End; - - ///添加页脚 - ///type:页眉类型,(default、even、first) - ///default, Header for odd pages or all if no even header. - ///first, Header for first page of section. - ///even, Header for even pages of recto/verso section. - Function AddFooter(type); - Begin - return _AddHeaderFooter('footer', (ifNil(type) or type = '') ? 'default' : type); - End; - - Function _AddHeaderFooter(headerFooter, hfType); - Begin - if headerFooter = 'header' then Begin - name := 'w:hdr'; - type := 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header'; - ContentType := 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'; - obj := _getHeaderFooter('w:headerReference', hfType); //页眉已经存在 - fileContent := ''; - End - else Begin - name := 'w:ftr'; - type := 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer'; - ContentType := 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'; - obj := _getHeaderFooter('w:footerReference', hfType); //页脚已经存在 - fileContent := ''; - End - if ifObj(obj) then return obj; - rels := zipfile_.Get('word/_rels/document.xml.rels'); - [rid, target] := class(TSXml).FindRelationshipRid(rels, '');//最大rId - rid ++; - files := sselect ['FileName'] from zipfile_.Files() where AnsiStartsText('word/' $ headerFooter, ['FileName']) end; - fid := length(files) + 1;//文件ID号 - target := headerFooter $ fid $ '.xml'; - class(TSXml).AddRelationshipRid(rels, target, type, 'rId'$rid, nil);//添加rId - PartName := '/word/' $ headerFooter $ fid $ '.xml'; - contentXml := zipfile_.Get('[Content_Types].xml'); - class(TSXml).AddOverrideContentType(contentXml, partName, contentType);//添加Contet_Types - fname := 'word/' $ headerFooter $ fid $ '.xml'; - zipfile_.Add(fname, fileContent);//创建页脚、页眉文件 - node := node_.InsertFirstChild('element', headerFooter = 'header' ? 'w:headerReference' : 'w:footerReference'); - node.SetAttribute('w:type', hfType); - node.SetAttribute('r:id', 'rId'$rid); - if hfType = 'first' then Begin - docGridNode := node_.FirstChildElement('w:docGrid'); - titlePg := node_.FirstChildElement('w:titlePg'); - if not ifObj(titlePg) then Begin - if ifObj(docGridNode) then - titlePg := node_.InsertBeforeChild(docGridNode,'element','w:titlePg'); - else - titlePg := node_.InsertEndChild('element','w:titlePg'); - End; - End; - - if hfType = 'even' then Begin - settingsXml := zipfile_.Get('word/settings.xml'); - if ifObj(settingsXml) then Begin - evenObj := settingsXml.FirstChildElement('w:settings').FirstChildElement('w:evenAndOddHeaders'); - if not ifObj(evenObj) then - evenObj := settingsXml.FirstChildElement('w:settings').InsertFirstChild('element','w:evenAndOddHeaders'); - evenObj.SetAttribute('w:val', 1); - End; - End; - return new TDocHeaderFooter(rid, zipfile_.Get(fname), name);//返回页脚、页眉对象 - End; - - Function _getRid(key, type); - Begin - if ifNil(type) or type = '' then - type := 'default'; - node := node_.FirstChildElement(key); - while ifObj(node) do Begin - name := node.GetName(); - if name = key then Begin - if type = node.GetAttribute('w:type') then - return node.GetAttribute('r:id'); - End; - node := node.NextElement(key); - End; - return ''; - End; - - Function _getHeaderFooter(key, type); - Begin - rid := _getRid(key, type); - if rid='' then return nil; - rels := zipfile_.Get('word/_rels/document.xml.rels'); - theNode := class(TSXml).FindRelationship(rels, rid); - if not ifObj(theNode) then - return nil; - fname := 'word/' $ theNode.GetAttribute('Target'); - xml := zipfile_.Get(fname); - if ifObj(xml) then - return new TDocHeaderFooter(rid, xml, key = 'w:headerReference' ? 'w:hdr' : 'w:ftr'); - return nil; - End; - - Index_:integer; - zipfile_; //压缩文件对象 -End; - -//node_ -> w:p/w:r/mc:AlternateContent/mc:Choice/mc:Fallback/w:pict/v:shape/v:textbox/w:txbxContent -Type TTextBox = Class(TDocumentBody, TTextBoxImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Class(TTextBoxImpl).Create(nil, 'w:txbxContent'); - Class(TDocumentBody).Create(node); - name_ := 'w:txbxContent'; - InitRootNode(node); - End; - - Function Create(pNode, name);overload; - Begin - Create(nil); - End; - - Function Init(pNode, nodeEx); - Begin - pNode_ := pNode; - NodeEx_ := nodeEx; - End; - - Function Apply();override; - Begin - if ifObj(NodeEx_) then Begin - data := node_.Marshal(); - NodeEx_.DeleteChildren(); - class(TSXml).UpdateNode(NodeEx_, data[0]['attributes'], data[0]['children']); - End; - End; - - Function Clear(); - Begin - if ifObj(node_) then node_.DeleteChildren(); - End; - - pNode_;// - NodeEx_;//w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/wps:txbxContent -End; - -//w:tr -Type TRow = Class(DocObject, TwTr) - Function Create(node); - Begin - node_ := node; - Class(TwTr).Create(nil, 'w:tr'); - End; - - Property Format read readFormat; - Function readFormat(); - Begin - return TrPr; - End; - - Property FormatEx read readFormatEx; - Function readFormatEx(); - Begin - return tblPrEx; - End; - - Function Apply();virtual; - Begin - arr := Marshal(); - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - End; -End; - -Type TFootnote = Class(TDocumentBody, TFootnoteImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - Class(TDocumentBody).Create(node); - Create(node, 'w:footnote'); - node_ := node; - End; - - Function Create(pNode, name);overload; - Begin - Class(TFootnoteImpl).Create(nil, name); - InitRootNode(pNode); - End; - - node_; -End; - -Type TFootnotes = Class - Function InitFootnotes(zip); - Begin - zip_ := zip; - file := 'word/footnotes.xml'; - footnotesXml_ := zip.Get(file); - idMap_ := array(); - maxId_ := 0; - if not ifObj(footnotesXml_) then - begin - content := ''; - zip_.Add(file, content); - footnotesXml_ := zip.Get(file); - // content_type - ctXml := zip_.Get('[Content_Types].xml'); - class(TSXml).AddOverrideContentType(ctXml, '/word/footnotes.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'); - // document.xml.rels - rels := zip_.Get('word/_rels/document.xml.rels'); - [maxRid, target, id] := class(TSXml).FindRelationshipRid(rels, ''); - maxRid++; - class(TSXml).AddRelationshipRid(rels, 'footnotes.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes', 'rId' $ maxRid); - end - footnotesNode_ := footnotesXml_.FirstChildElement("w:footnotes"); - node := footnotesNode_.FirstChildElement('w:footnote'); - while ifObj(node) do - begin - obj := new TFootnote(node); - id := obj.Value('Id', true); - idMap_[id] := obj; - id := StrToIntDef(id, 0); - if id > maxId_ then maxId_ := id; - node := node.NextElement(); - end - End; - - Function Add(); - Begin - node := footnotesNode_.InsertEndChild('element', 'w:footnote'); - node.SetAttribute('w:id', ++maxId_); - obj := new TFootnote(node); - obj.Id := maxId_; - idMap_[maxId_] := obj; - return obj; - End; - - Function GetFootnote(id); - Begin - return idMap_[id]; - End; - - Function CopyFootnote(obj); - Begin - marshal := obj.Root().Marshal()[0]; - node := footnotesNode_.InsertEndChild(marshal); - node.SetAttribute('w:id', ++maxId_); - obj := new TFootnote(node); - obj.Id := maxId_; - idMap_[maxId_] := obj; - return obj; - End; - -private - zip_; - footnotesXml_; - footnotesNode_; - idMap_; - maxId_; -End; - -//w:tc -Type TCell = Class(TDocumentBody, TWTc) - Function Create();overload; - Begin - Create(nil); - End; - Function Create(node);overload; - Begin - Class(TDocumentBody).Create(node); - Create(node, 'w:tc'); - End; - - Function Create(pNode, name);overload; - Begin - Class(TWTc).Create(nil, 'w:tc'); - InitRootNode(pNode); - name_ := 'w:tc'; - mergeSpan_ := 0; - pPr_ := new TwpPr(); - End; - - Property Format read readFormat; - Function readFormat(); - Begin - return TcPr; - End; - - Property PFormat read readPFormat; - Function readPFormat(); - Begin - return pPr_; - End; - - Function Apply(); override; - Begin - arr := Marshal(); - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - - arr := pPr_.Marshal(); - if length(arr['attributes']) or length(arr['children']) then Begin - pNode := node_.FirstChildElement('w:p'); - while ifObj(pNode) do Begin - pPr := class(TSXml).GetNode(pNode, 'w:pPr', 'first'); - class(TSXml).UpdateNode(pPr, arr['attributes'], arr['children']); - pNode := pNode.NextElement(); - End; - End; - End; - - ///添加文字 - Function SetText(txt); - Begin - if not ifString(txt) then - lines := array('' $ txt); - else - lines := str2array(txt, '\n'); - for i:=0 to length(lines)-1 do Begin - newp := new TParagraph(); - newp.pPr.rPr.Lang := 'en-US'; - newp.pPr.rPr.eastAsia := 'zh-CN'; - newp.Run.rPr.Lang := 'en-US'; - newp.Run.rPr.eastAsia := 'zh-CN'; - newp.Run.SetText( lines[i] ); - NewChildNode( array("field":"", "name":"w:p", "obj":newp, "attrEx":"", "nodeType":"") ); - End; - if not istable(lines) then - P.Run.T := ''; - End; - - Function Clear(); - Begin - node := node_.FirstChildElement('w:p'); - while ifObj(node) do Begin - n := node.NextElement(); - if ind = 0 then - node.DeleteChildren(); - else - node_.DeleteChild(node); - ind++; - node := n; - End; - End; - - Function Row(); - Begin - return new TRow(node_.Parent()); - End; - - Function Append(c); - Begin - ps := c.Parts(); - for i:=0 to length(ps)-1 do Begin - if not ps[i].node_.GetName() in array('w:p', 'w:tbl') then continue; - data := ps[i].node_.Marshal(); - w := node_.InsertEndChild(data[0]); - End; - End; - - mergeSpan_:integer; - pPr_;//段落格式 -End; - -//w:tbl -Type TTable = Class(DocObject, TTableImpl) - Function Create();overload; - Begin - Create(nil); - End; - - Function Create(node);overload; - Begin - name_ := 'w:tbl'; - Class(TTableImpl).Create(nil, 'w:tbl'); - if ifObj(node) then - Init(node); - End; - - Function Root();override; - Begin - return node_; - End; - - Function Init(node); - Begin - node_ := node; - cells_ := array(); - iCol_ := 0; - row := node.FirstChildElement('w:tr'); - while ifObj(row) do Begin - col := row.FirstChildElement('w:tc'); - iCol := 0; - while ifObj(col) do Begin - //c := new TCell(col); - cells_[iRow, iCol] := array(col, 0); - iCol ++; - mergeSpan := _getVSpan(col);//合并单元格 - if mergeSpan > 0 then Begin - //c.mergeSpan_ := mergeSpan; - cells_[iRow, iCol, 1] := mergeSpan; - for j:=1 to mergeSpan-1 do Begin - cells_[iRow, iCol] := nil; - iCol ++; - End; - End; - if iCol > iCol_ then iCol_ := iCol; - col := col.NextElement('w:tc'); - End; - iRow ++; - row := row.NextElement('w:tr'); - End; - InitRootNode(node); - End; - - Function GetCell(r, c); - Begin - return cells_[r-1, c-1]; - End; - - ///设置表格数据 - ///data: table,数据表 - ///[includeHeader: bool] 是否包括表头,默认FALSE - ///[includeIndex: bool] 是否自动添加索引号,默认FALSE - Function SetData(docx, data, includeHeader, includeIndex); - Begin - if not IsTable(data) then - raise "Invalid Data."; - [rowcount,colcount] := mSize(data);//一维数组 - if colcount = 0 then - data := array(data); - fields := FieldNames(data); - if IsTable(fields) then Begin - r := nils(length(data),length(fields)); - r[:,:] := data; - data := r; - End; - if includeIndex then Begin - n := length(data)-1; - r := array(0->n); - data := `r | data; - End; - if includeHeader and IsTable(fields) then Begin - if includeIndex then - fields := array("Index") union fields; - data := array(fields) union data; - End; - Data_ := data; - TblPr.StyleId := _GetStyle(docx, 'normaltable'); - TblPr.Width := 0; - TblPr.WidthType := 'auto'; - //TblPr.Borders.Top.Val := 'single'; - //TblPr.Borders.Left.Val := 'single'; - //TblPr.Borders.Bottom.Val := 'single'; - //TblPr.Borders.Right.Val := 'single'; - //TblPr.Borders.InsideH.Val := 'single'; - //TblPr.Borders.InsideV.Val := 'single'; - //TblPr.CellMar.Top := 0; - //TblPr.CellMar.Left := 108; - //TblPr.CellMar.Bottom := 0; - //TblPr.CellMar.Right := 108; - //TblPr.CellMar.TopType := 'dxa'; - //TblPr.CellMar.LeftType := 'dxa'; - //TblPr.CellMar.BottomType := 'dxa'; - //TblPr.CellMar.RightType := 'dxa'; - //TblPr.FirstColumn := 1; - //TblPr.FirstRow := 1; - //TblPr.LastColumn := 0; - //TblPr.LastRow := 0; - //TblPr.NoVBand := 1; - //TblPr.NoHBand := 0; - //TblPr.Val := '04A0'; - - width := getBlockWidth(docx); - [rowCount, cnt] := MSize(data); - colCount_ := cnt; - colWidth_ := colCount_ ? integer(width / colCount_) : 0; - gridArr := array(); - for i:=0 to colCount_-1 do Begin - gcol := new TwGridCol(); - gcol.W := colWidth_; - gridArr union= array(('name':'w:gridCol','obj':gcol,'attrEx':'','nodeType':'','attrName':'')); - End; - TblGrid.GridCol := gridArr; - End; - - Function _GetStyle(obj, id); - Begin - style := obj.StyleObject().GetStyleById(id); - if not ifObj(style) then Begin - style := obj.StyleObject().AddDefaultStyle(id); - End; - return style.StyleId; - End; - - Property Format read readFormat; - Function readFormat(); - Begin - return TblPr; - End; - - Property Paragraph read readParagraph; - Function readParagraph(); - Begin - if not ifObj(paragraph_) then - paragraph_ := new TParagraph(); - return paragraph_; - End; - - Property FormatEx read readFormatEx; - Function readFormatEx(); - Begin - return TblPr.tblpPr; - End; - - ///修改表格属性 - Function Apply(); override; - Begin - arr := Marshal(); - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - End; - - ///列数 - Function Cols(); - Begin - return iCol_; - End; - - ///行数 - Function Rows(); - Begin - return length(cells_); - End; - - ///获取单元格 - Function Cell(row, col); - Begin - if row > length(cells_) then return nil; - c := cells_[row-1, col-1]; - if ifNil(c) then return nil; - cellObj := new TCell(c[0]); - cellObj.mergeSpan_ := c[1]; - return cellObj; - End; - - ///设置列宽 - Function ColumnWidth(n, wth); - Begin - if n >0 and n <= length(TblGrid.GridCol) then - TblGrid.GridCol[n-1]['obj'].W := wth; - End; - - /// 设置行高 - Function RowHeight(row, height); - Begin - if row <= 0 or row > Rows() then return; - node := _getRowNode(row - 1); - node := class(TSXml).GetNode(node, 'w:trPr/w:trHeight', 'end'); - node.SetAttribute('w:hRule', 'exact'); - node.SetAttribute('w:val', height); - End; - - Function Height(row); - Begin - if row <= 0 or row > Rows() then return nil; - node := _getRowNode(row - 1); - obj := new TwTr(); - obj.InitRootNode(node); - return obj.TrPr.Value('Height'); - End; - - Function Width(col); - Begin - obj := Cell(1, col); - return obj.Format.Value('Width'); - End; - - ///合并单元格 - ///del: bool,是否删除其它单元格内容(只保留左上单元格内容) - Function Merge(top, left, bottom, right, del);overload; - Begin - // - // - rowCount := Rows(); - if left > right or top > bottom or left > iCol_ or top > rowCount or (left = right and top = bottom) then - return 'Invalid input param.'; - //合并其它单元格 - [left2, right2, top2, bottom2] := array(left, right, top, bottom); - //println('merge(left2, right2, top2, bottom2)={}',array(left2, right2, top2, bottom2)); - for i:=left to right do Begin - if top > 1 then Begin - c1 := Cell(top - 1, i); - c2 := Cell(top, i); - if (c2 = nil or c2.mergeSpan_ > 0) and (c1 = nil or c1.mergeSpan_ > 0) then Begin - top2 := _getTop(top - 1, i, top2); - End; - End; - - if bottom < rowCount then Begin - c1 := Cell(bottom, i); - c2 := Cell(bottom + 1, i); - if (c2 = nil or c2.mergeSpan_ > 0) and (c1 = nil or c1.mergeSpan_ > 0) then Begin - bottom2 := _getBottom(bottom + 1, rowCount, i, bottom2); - End; - End; - End; - for i:=top to bottom do Begin - if left > 1 then Begin - c1 := Cell(i, left - 1); - c2 := Cell(i, left); - if c2 = nil and (c1 = nil or c1.mergeSpan_ > 0) then - left2 := _getLeft(i, left - 1, left2); - End; - - if right < iCol_ then Begin - c1 := Cell(i, right); - c2 := Cell(i, right + 1); - if c2 = nil and (c1 = nil or c1.mergeSpan_ > 0) then - right2 := _getRight(i, right + 1, right2); - End; - End; - //println('merge(left2, right2, top2, bottom2)={}\n',array(left2, right2, top2, bottom2)); - val := right2 - left2 + 1; - theCell := Cell(top2, left2); - for row:=top2 to bottom2 do Begin - c := Cell(row, left2); - c.mergeSpan_ := val; - gridSpan := class(TSXml).GetNode(c.node_, 'w:tcPr/w:gridSpan', true); - gridSpan.SetAttribute('w:val', val); - node := class(TSXml).GetNode(c.node_, 'w:tcPr/w:vMerge', true); - node.SetAttribute('w:val', row=top2 ? 'restart' : 'continue'); - if row <> top2 then Begin - if not del then - theCell.Append(c); - c.Clear(); - End; - - for col:=left2 + 1 to right2 do Begin - c := Cell(row, col); - if ifObj(c) then Begin - if not del then - theCell.Append(c); - c.node_.Parent().DeleteChild(c.node_); - cells_[row-1, col-1] := nil; - End; - End; - End; - - return 'ok'; - End; - - ///合并单元格 - ///hcell: string,左上角坐标,eg: 'B2' - ///vcell: string,右下角坐标,eg: 'C4' - ///del: bool,是否删除其它单元格内容(只保留左上单元格内容) - Function Merge(hCell, vCell, del);overload; - Begin - [err1, left, top] := CellNameToCoordinates(hCell); - [err2, right, bottom] := CellNameToCoordinates(vCell); - if err1 or err2 then - return 'Invalid input Coordinates.'; - return Merge(top, left, bottom, right, del); - End; - - ///删除单元格 - ///row: int, 行 - ///col: int, 列 - ///[cellshift]: int, 默认1。0:删除单元格下方内容上移,1:删除单元格右侧单元格左移 - ///row或col其中一个为nil时,删除某行或某列,如(1, nil),删除第一行 - Function DeleteCell(row, col, cellshift); - Begin - if ifnil(cellshift) then cellshift := 1; - if ifnumber(row) and ifnil(col) then - begin - node := _getRowNode(row - 1); - if ifObj(node) then node_.DeleteChild(node); - for i:=row-1 to length(cells_)-2 do - cells_[i] := cells_[i + 1]; - reindex(cells_, array(length(cells_)-1 : nil)); - end - else if ifnil(row) and ifnumber(col) then - begin - for r:=1 to length(cells_) do - DeleteCell(r, col); - iCol_--; - end - else begin - c := cells_[row-1, col-1]; - if not c then return; - node := _getRowNode(row - 1); - if cellshift then - begin - node.DeleteChild(c[0]); - for i:=col-1 to iCol_ - 1 do - cells_[row-1, i] := cells_[row-1, i+1]; - cells_[row-1, iCol_-1] := nil; - end - else begin - r := row; - len := length(cells_); - while r < len and ifObj(node) do - begin - tcell := cells_[r, col-1]; - if tcell then - begin - new_node := node.InsertAfterChild(c[0], tcell[0].Marshal()[0]); - node.DeleteChild(c[0]); - cells_[row-1, col-1, 0] := new_node; - end - c := tcell; - ++r; - node := node.NextElement(); - end - if c then - begin - p := c[0].FirstChild('w:p'); - c[0].DeleteChildren(); - c[0].InsertEndChild('element', 'w:p'); - end - end - end - End; - - ///设置表格样式ID - ///docx: TSDocxFile对象 - ///styleId: 表格样式ID - Function SetStyleById(docx, styleId); - Begin - ret := array(); - _getTblStylePr(docx, styleId, ret); - tblPr.StyleId := styleId; - Apply(); - for i:=0 to length(ret)-1 do - begin - cnf := TOfficeObj('TwCnfStyle'); - cnf.Val := 000000000000; - cnf.FirstRow := 0; - cnf.LastRow := 0; - cnf.FirstColumn := 0; - cnf.LastColumn := 0; - cnf.OddVBand := 0; - cnf.EvenVBand := 0; - cnf.OddHBand := 0; - cnf.EvenHBand := 0; - cnf.FirstRowFirstColumn := 0; - cnf.FirstRowLastColumn := 0; - cnf.LastRowFirstColumn := 0; - cnf.LastRowLastColumn := 0; - - case ret[i] of - 'firstRow': - begin - node := _getRowNode(0); - trPr := node.FirstChild('w:trPr'); - twtrpr := TOfficeObj('TwTrPr'); - twtrpr.InitRootNode(trPr); - cnf.Val := 100000000000; - cnf.FirstRow := 1; - twtrpr.CnfStyle := cnf; - twtrpr.Update(); - end - 'lastRow': - begin - node := _getRowNode(Rows()-1); - trPr := node.FirstChild('w:trPr'); - twtrpr := TOfficeObj('TwTrPr'); - twtrpr.InitRootNode(trPr); - cnf.Val := 010000000000; - cnf.LastRow := 1; - twtrpr.CnfStyle := cnf; - twtrpr.Update(); - end - end; - end - End; - - Function _getTblStylePr(docx, id, ret); - Begin - style_obj := docx.StyleObject().GetStyleById(id); - if not ifObj(style_obj) then return; - tbl_style_pr := style_obj.Root().FirstChild('w:tblStylePr'); - while ifObj(tbl_style_pr) do - begin - wtype := tbl_style_pr.GetAttribute('w:type'); - ret[length(ret)] := wtype; - tbl_style_pr := tbl_style_pr.NextElement('w:tblStylePr'); - end - base := style_obj.Value('BasedOn'); - _getTblStylePr(docx, base, ret); - End; - - Function _getRowNode(row); - Begin - node := node_.FirstChild('w:tr'); - while row and ifObj(node) do - begin - row--; - node := node.NextElement('w:tr'); - end - return node; - End; - - Function _getLeft(row, iCol, left2); - Begin - for i:=iCol downto 1 do Begin - c := Cell(row, i); - if ifObj(c) then Begin - if i < left2 then - left2 := i; - break; - End; - End; - return left2; - End; - - Function _getRight(row, iCol, right2); - Begin - for i:=iCol to iCol_ do Begin - c := Cell(row, i); - if ifObj(c) then - break; - if i > right2 then - right2 := i; - End; - return right2; - End; - - Function _getTop(top, iCol, top2); - Begin - for i:=top downto 1 do Begin - c := Cell(i, iCol); - if ifObj(c) and c.mergeSpan_ < 1 then Begin - break; - End; - if i < top2 then - top2 := i; - End; - return top2; - End; - - Function _getBottom(bottom, rowCount, iCol, bottom2); - Begin - for i:=bottom to rowCount do Begin - c := Cell(i, iCol); - if ifObj(c) and c.mergeSpan_ < 1 then Begin - break; - End; - if i > bottom2 then - bottom2 := i; - End; - return bottom2; - End; - - Function _getVSpan(node); - Begin - vMerge := class(TSXml).GetNode(node, 'w:tcPr/w:vMerge'); - if ifObj(vMerge) and vMerge.GetAttribute('w:val') in array('restart', 'continue') then Begin - nSpan := class(TSXml).GetNode(node, 'w:tcPr/w:gridSpan'); - if ifObj(nSpan) then Begin - return strtoint(nSpan.GetAttribute('w:val')); - End; - End; - return -1; - End; - - Function getBlockWidth(docx); - Begin - sectPr := docx.Body().node_.FirstChildElement('w:sectPr'); - try - width := sectPr.FirstChildElement('w:pgSz').GetAttribute('w:w'); - left := sectPr.FirstChildElement('w:pgMar').GetAttribute('w:left'); - right := sectPr.FirstChildElement('w:pgMar').GetAttribute('w:right'); - return strtoint(width) - strtoint(left) - strtoint(right); - except - End; - return strtoint(width); - End; - - iCol_:integer; - cells_; - Data_; - colCount_; - colWidth_; - paragraph_;//缺省单元格段落格式、字体格式 -End; - -Type TCoreProperties = Class(DocObject) - Property Author read readAuthor write writeAuthor; - Property Category read readCategory write writeCategory; - Property Description read readDescription write writeDescription; - Property Subject read readSubject write writeSubject; - Property Title read readTitle write writeTitle; - Property Version read readVersion write writeVersion; - Property Rversion read readRversion write writeRversion; - Property KeyWords read readKeyWords write writeKeyWords; - Property Created read readCreated write writeCreated; - Property Modified read readModified write writeModified; - Property LastModifiedBy read readLastModifiedBy write writeLastModifiedBy; -private - Function readAuthor(); - Begin - return propValue('dc:creator'); - End; - - Function readCategory(); - Begin - return propValue('cp:category'); - End; - - Function readDescription(); - Begin - return propValue('dc:description'); - End; - - Function readSubject(); - Begin - return propValue('dc:subject'); - End; - - Function readTitle(); - Begin - return propValue('dc:title'); - End; - - Function readVersion(); - Begin - return propValue('cp:version'); - End; - - Function readRversion(); - Begin - return propValue('cp:rversion'); - End; - - Function readKeyWords(); - Begin - return propValue('cp:keywords'); - End; - - Function readLastModifiedBy(); - Begin - return propValue('cp:lastModifiedBy'); - End; - - Function readCreated(); - Begin - return propValue('dcterms:created'); - End; - - Function readModified(); - Begin - return propValue('dcterms:modified'); - End; - - Function propValue(k); - Begin - node := class(TSXml).GetNode(node_, k); - if not ifObj(node) then return ''; - return class(TSXml).Utf8ToCurCodePage( node.GetText() ); - End; - - Function propNode(k); - Begin - n := node_.FirstChildElement(k); - if ifObj(n) then return n; - return node_.InsertEndChild('element', k); - End; - - Function writeAuthor(v); - Begin - return propNode('dc:creator').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeCategory(v); - Begin - return propNode('cp:category').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeDescription(v); - Begin - return propNode('dc:description').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeSubject(v); - Begin - return propNode('dc:subject').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeTitle(v); - Begin - return propNode('dc:title').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeVersion(v); - Begin - return propNode('cp:version').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeRversion(v); - Begin - return propNode('cp:rversion').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeKeyWords(v); - Begin - return propNode('cp:keywords').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeLastModifiedBy(v); - Begin - return propNode('cp:lastModifiedBy').SetValue(class(TSXml).CurCodePageToUtf8(v)); - End; - - Function writeCreated(v); - Begin - return propNode('dcterms:created').SetValue(class(TSXml).GetDatetimeStr(v)); - End; - - Function writeModified(v); - Begin - return propNode('dcterms:modified').SetValue(class(TSXml).GetDatetimeStr(v)); - End; -End; - -//w:latentStyles -// Attributes(w:name、w:count、w:defLockedState、w:defQFormat、w:defSemiHidden、w:defUIPriority、w:defUnhideWhenUsed) - - -//w:style -// 'w:name', 'w:aliases', 'w:basedOn', 'w:next', 'w:link', -// 'w:autoRedefine', 'w:hidden', 'w:uiPriority', 'w:semiHidden', -// 'w:unhideWhenUsed', 'w:qFormat', 'w:locked', 'w:personal', -// 'w:personalCompose', 'w:personalReply', 'w:rsid', 'w:pPr', 'w:rPr', -// 'w:tblPr', 'w:trPr', 'w:tcPr', 'w:tblStylePr' -Type TDocxStyle = Class(TDocxStyleImpl) - Function Create(); overload; - Begin - create(nil); - End; - - Function Create(node); overload; - Begin - Init(node); - Class(TDocxStyleImpl).Create(nil, 'w:style'); - End; - - Function Init(node); - Begin - if ifObj(node) then Begin - node_ := node; - wType := node.GetAttribute('w:type'); - styleId := node.GetAttribute('w:styleId'); - nameObj := node.FirstChildElement('w:name'); - if ifObj(nameObj) then - Name := nameObj.GetAttribute('w:val'); - InitRootNode(node); - End; - End; - - ///显示大纲级别 - Function HeadingLevel(); - Begin - node := class(TSXml).GetNode(node_, 'w:pPr/w:outlineLvl'); - if ifObj(node) then - return node.GetAttribute('w:val'); - return ''; - End; - - Function ReadPprFormat(); - Begin - if ifObj(pPr_) then - return pPr_; - pPr_ := Class(TSXml).ReadPprFormat(node_); - return pPr_; - End; - - Function ReadRprFormat(); - Begin - if ifObj(rPr_) then - return rPr_; - rPr_ := Class(TSXml).ReadRprFormat(node_); - return rPr_; - End; - - Function Apply(); - Begin - if ifObj(rPr_) then Begin - arr := rPr_.Marshal(); - if length(arr['attributes']) or length(arr['children']) then Begin - class(TSXml).UpdateNode(rPr_.Root(), arr['attributes'], arr['children']); - End; - End; - - if ifObj(pPr_) then Begin - arr := pPr_.Marshal(); - if length(arr['attributes']) or length(arr['children']) then Begin - class(TSXml).UpdateNode(pPr_.Root(), arr['attributes'], arr['children']); - End; - End; - - arr := self.Marshal(); - if length(arr['attributes']) or length(arr['children']) then Begin - class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); - End; - End; - - node_; - pPr_; - rPr_; -End; - -Type TNumStyle = Class(TNumStyleImpl) - Function Create(); overload; - Begin - create(nil); - End; - - Function Create(node); overload; - Begin - Init(node); - Class(TNumStyleImpl).Create(nil, 'w:num'); - End; - - Function Init(node); - Begin - if ifObj(node) then Begin - node_ := node; - abstractNumId := node.GetAttribute('w:abstractNumId'); - typeNode := node.FirstChildElement('w:multiLevelType'); - if ifObj(typeNode) then - multiLevelType := typeNode.GetAttribute('w:val'); - fmtNode := class(TSXml).GetNode(node, 'w:lvl/w:numFmt'); - if ifObj(fmtNode) then - numFmt := fmtNode.GetAttribute('w:val'); - InitRootNode(node); - End; - End; - - Function Root();override; - Begin - return node_; - End; - - ///数字项目编号样式ID - Function Id(); - Begin - return abstractNumId; - End; - - ///数字项目编号字符串 - Function GetText(ilvl, arr); - Begin - if numFmt = 'bullet' then - return ''; - if not ifarray(levels_) then Begin - levels_ := array(); - node := node_.FirstChildElement('w:lvl'); - while ifObj(node) do Begin - startObj := node.FirstChildElement('w:start'); - fmtObj := node.FirstChildElement('w:numFmt'); - textObj := node.FirstChildElement('w:lvlText'); - start := ifObj(startObj) ? Class(TSXml).SafeStrToIntDef(startObj.GetAttribute('w:val'), 1) : 1; - fmt := ifObj(fmtObj) ? fmtObj.GetAttribute('w:val') : ''; - lvlText := ifObj(textObj) ? textObj.GetAttribute('w:val') : ''; - levels_[length(levels_)] := array('node':node, 'text':lvlText, 'numFmt':fmt, 'start':start); - node := node.NextElement('w:lvl'); - End; - End; - if ilvl < 0 or ilvl >= length(levels_) then - return ''; - str := levels_[ilvl]['text']; - for i:=ilvl downto 0 do Begin - srcFmt := '%' $ (i + 1); - destStr := _getNumStr(arr[i], levels_[i]['numFmt'], levels_[i]['start']-1); - str := ReplaceStr(str, srcFmt, destStr); - End; - return str; - End; - - Function _getNumStr(index, fmt, start); - Begin - num := index + start; - if fmt = 'decimal' or num >= 10000 then //数字项目编号 14.1.1 - return '' $ num; - //中文编号 - chNum := array('零','一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五','十六','十七','十八','十九'); - if num < 20 then - return chNum[num]; - v4 := int(num/1000); - s4 := v4 ? chNum[v4] + '千' : ''; - v3 := int((num % 1000) / 100); - s3 := v3 ? chNum[v3] + '百' : (s4 <> '' ? '零' : ''); - v2 := int((num % 100) / 10); - s2 := v2 ? chNum[v2] + '十' : ((s4+s3) <> '' ? '零' : ''); - v1 := num % 10; - s1 := v1 ? chNum[v1] : ''; - if s3='零' and s2='零' then s3 := ''; - if s1='' and s2='零' then s2 := ''; - return s4 + s3 + s2 + s1; - End; - - numFmt; - node_; - levels_; -End; - -Function _getDocObject(node, name); -Begin - p := nil; - case name of - 'w:del','w:ins': - p := new TRevision(node); - 'w:p': - p := new TParagraph(node); - 'w:tbl': - p := new TTable(node); - 'w:r': - p := new TRun(); - End; - if ifObj(p) then Begin - p.node_ := node; - p.name_ := name; - End; - return p; -End; - -///返回全部列表 -Function getDocumentObjects(parent, prefix); -Begin - ps := array(); - node := parent.FirstChildElement(); - while ifObj(node) do Begin - name := node.GetName(); - if length(prefix) = 0 or (ifstring(prefix) and name = prefix) or (istable(prefix) and (name in prefix)) then Begin - p := _getDocObject(node, name); - if p = nil then Begin - p := new DocObject(); - p.node_ := node; - p.name_ := name; - End; - ps[ length(ps) ] := p; - End; - node := node.NextElement(); - End; - return ps; -End; - -Function getDocumentObject(parent, prefix, index); -Begin - node := parent.FirstChildElement(); - cnt := 0; - while ifObj(node) do Begin - name := node.GetName(); - if length(prefix) = 0 or (ifstring(prefix) and name = prefix) or (istable(prefix) and (name in prefix)) then Begin - if cnt then Begin //第index个对象 - p := _getDocObject(node, name); - if ifObj(p) then Begin - return p; - End; - End; - cnt ++; - End; - node := node.NextElement(); - End; - return nil; -End; - -Function _text(r); -Begin - txt := ''; - for i:= 0 to length(r)-1 do Begin - if i and r[i]['pIndex'] > 0 and r[i]['pIndex'] <> r[i-1]['pIndex'] then - txt += '\n'; - if ifObj(r[i]['rNode']) then Begin - run := new TRun(r[i]['rNode']); - txt += run.Text(); - End; - End; - return txt; -End; - -Function _getHanging(linesCnt, pPr); -Begin - wth := pPr.LeftIndent + pPr.RightIndent; - if linesCnt = 0 then Begin - if pPr.Hanging then - wth -= pPr.Hanging; - else if pPr.FirstLineIndent then - wth += pPr.FirstLineIndent; - End; -//_dumpPpr(pPr); -//println('>>>>>行首,lines={}, wth={}', linesCnt, wth); - return wth; -End; - -Function _dumpPpr(pPr); -Begin - if not ifObj(pPr) then - return println('pPr is null'); - println('SpaceBefore={},SpaceAfter={},LineSpacing={},LineSpacingRule={},Left={},Right={},Hanging={},FirstLineIndent={}', - pPr.SpaceBefore, pPr.SpaceAfter, pPr.LineSpacing,pPr.LineSpacingRule,pPr.LeftIndent,pPr.RightIndent,pPr.Hanging,pPr.FirstLineIndent); -End; - -Function _dumpRpr(rPr); -Begin - if not ifObj(rPr) then - return println('rPr is null'); - println('sz={},szCs={},hint={},eastAsia={}', - rPr.Size,rPr.szCs,rPr.rFont.hint,rPr.rFont.eastAsia); -End; - -//文本前后是否包含空格 -Function _preserve(str); -Begin - if not ifstring(str) then return false; - cnt := length(str); - spaceArr := array(' ',' '); - if cnt and (str[1] in spaceArr or (cnt > 1 and str[cnt] in spaceArr)) then - return true; - return false; -End; - +/////////////////////////////////////////////////////////////////////////////////////////// +///DOCX文档实现 + +Type TRange = Class + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(t);overload; + Begin + //array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r)) + Init(t); + End; + + Function Init(t); + Begin + RunArr_ := t; + End; + + ///清除全部选中内容 + Function Clear(); + Begin + _clear(0);//清除全部w:r + End; + + Property Font read readFont; + Function readFont(); + Begin + if ifNil(rPr_) then + rPr_ := new TwrPr(); + return rPr_; + End; + + Property Text read readText write writeText; + Function readText(); + Begin + return _text(RunArr_); + End; + + Function writeText(txt); + Begin + r := RunArr_[0:0,:]; + _clear(1);//只保留第1段 + run := new TRun(r[0]['rNode']); + run.SetText(txt); + return r; + End; + + ///应用字体样式 + Function Apply(); + Begin + if not ifObj(rPr_) then return; + arr := rPr_.Marshal(); + if length(arr['attributes']) or length(arr['children']) then Begin + for i:=0 to length(RunArr_)-1 do Begin + rPr := class(TSXml).GetNode(RunArr_[i]['rNode'], 'w:rPr', 'first'); + class(TSXml).UpdateNode(rPr, arr['attributes'], arr['children']); + End; + End; + End; + + Function _clear(first); + Begin + for i:=first to length(RunArr_)-1 do Begin + pNode := RunArr_[i]['pNode']; + pNode.DeleteChild(RunArr_[i]['rNode']); + rNode := pNode.FirstChildElement('w:r'); + if not ifObj(rNode) then + pNode.Parent().DeleteChild(pNode); + End; + End; + + rPr_;//字体格式 + RunArr_; +End; + +Type DocObject = Class + Function Create(); + Begin + pageNo_ := 0; + linePos_ := 0.; + End; + + Function Name(); + Begin + return name_; + End; + + ///修改属性,包括样式、边框、底纹、字体等 + Function Apply();virtual; + Begin + End; + + ///前一个对象 + Function Prev();virtual; + Begin + return _next_prev_Impl(node_.PrevElement(name_)); + End; + + ///下一个对象 + Function Next();virtual; + Begin + return _next_prev_Impl(node_.NextElement(name_)); + End; + + ///添加批注 + ///obj:TDocComment对象 + ///返回:成功 true + Function AddComment(obj); + Begin + id := obj.ID; + r := _split_range(obj.sPos, obj.SelectLength); + cnt := length(r); + if cnt then Begin + rNode := r[0]['rNode']; + beg := rNode.Parent().InsertBeforeChild(rNode, 'element', 'w:commentRangeStart'); + beg.SetAttribute('w:id', id); + + rNode := r[cnt-1]['rNode']; + eNode := rNode.Parent().InsertAfterChild(rNode, 'element', 'w:commentRangeEnd'); + eNode.SetAttribute('w:id', id); + + r := rNode.Parent().InsertAfterChild(eNode, 'element', 'w:r'); + cr := r.InsertFirstChild('element', 'w:commentReference'); + cr.SetAttribute('w:id', id); + return true; + End; + return false; + End; + + ///修订插入 + ///obj:TRevision对象 + ///返回:成功 true + Function AddRevision(obj); + Begin + obj.NodeName := 'w:ins'; + obj.name_ := obj.NodeName; + r := _split_range(obj.sPos, 0); + if length(r) then Begin + rNode := r[length(r)-1]['rNode']; + node := rNode.Parent().InsertAfterChild(rNode, obj.Marshal()); + End + else Begin + pPr := node_.FirstChildElement('w:pPr'); + if ifObj(pPr) then + node := node_.InsertAfterChild(pPr, obj.Marshal()); + else + node := node_.InsertFirstChild(obj.Marshal()); + rNode := node.NextElement('w:r'); + End; + if ifObj(rNode) then Begin + data := rNode.Marshal(); + node2 := node.InsertFirstChild(data[0]); + End + else Begin + node2 := node.InsertEndChild('element', 'w:r'); + End; + run := new TRun(node2); + run.SetText(obj.InsText_, true); + obj.Init(node); + return true; + End; + + ///修订删除 + ///obj:TRevision对象 + ///返回:成功 true,失败 false + Function DelRevision(obj); + Begin + r := _split_range(obj.sPos, obj.SelectLength); + for i:=0 to length(r)-1 do Begin + rNode := r[i]['rNode']; + delNode := rNode.Parent().InsertAfterChild(rNode, obj.Marshal()); + rXml := string(rNode.Data()); + rXml := ReplaceStr(rXml, '', ''); + delNode.InsertFirstChild(rXml); + rNode.Parent().DeleteChild(rNode); + End; + return length(r); + End; + + Function _next_prev_Impl(n); + Begin + if ifObj(n) then Begin + case name_ of + 'w:p': + p := new TParagraph(p); + 'w:tbl': + p := new TTable(n); + 'w:r': + p := new TRun(n); + 'w:del','w:ins': + p := new TRevision(n); + End; + if ifObj(p) then Begin + p.name_ := name; + p.node_ := n; + End; + End; + return p; + End; + + ///文本内容 + Function Text();virtual; + Begin + r := TextArray(); + return _text(r); + End; + + //所有文字信息(包括位置信息) + //返回:table(包括w:r节点) + Function TextArray();virtual; + Begin + r := array(); + node := node_.FirstChildElement('w:r'); + while ifObj(node) do Begin + r[ind]['pNode'] := node_; + r[ind]['pIndex'] := -1; + r[ind]['rNode'] := node; + r[ind]['rIndex'] := ind; + ind++; + node := node.NextElement('w:r'); + End; + return r; + End; + + ///段落中插入文字 + Function AddText(sPos, txt); + Begin + if sPos < 0 then Begin //段落后追加 + lastNode := node_.LastChild('w:r'); + if ifObj(lastNode) then Begin + rNode := _duplicate_r(lastNode); + End + else Begin + rNode := node_.InsertEndChild('element','w:r'); + p := new TParagraph(node_); + p.CopyRunFormat(false, rNode); + End; + run := new TRun(rNode); + run.SetText(txt); + t := array(('pNode':node_, 'pIndex':-1, 'rNode':rNode, 'rIndex':-1)); + return new TRange(t); + End; + obj := new TRevision(); + obj.sPos := sPos; + obj.InsText := txt; + AddRevision(obj);//插入文字 + t := obj.Accept(); + return new TRange(t); + End; + + ///返回:TRange对象,(TBody、TParagraph、TCell)全部内容 + Function Range();overload; + Begin + t := TextArray(); + if not istable(t) then + return nil; + return new TRange(t); + End; + + ///sPos:起始位置 + ///rangeLength:内容长度 + ///返回:TRange对象,此函数非只读,执行此函数会重新调整段落中TRun结构 + Function Range(sPos, rangeLength);overload; + Begin + t := _split_range(sPos, rangeLength); + if not istable(t) then + return nil; + return new TRange(t); + End; + + ///返回文档中的位置 + Function Node(); + Begin + return node_; + End; + + Function _split_range(sPos, rangeLength); + Begin + t := array(); + if not ifInt(sPos) or not ifInt(rangeLength) or sPos < 0 then + return t; + r := TextArray(); + rSize := 0; + for i:=0 to length(r)-1 do Begin + run := new TRun(r[i]['rNode']); + txt := run.Text(); + if class(TSXml).IsUtf8() then + txt := UTF8ToAnsi(txt); + txtLen := lengthW(txt); + if rangeLength >= 0 and sPos + rangeLength <= rSize then Begin + return t; + End; + if rangeLength = 0 then Begin //w:ins情况 + if sPos >= txtLen + rSize then Begin //前 + rSize += txtLen; + t[0] := r[i]; + End + else Begin //一分为二,取头部 + if sPos = rSize then + return t;//正好文档开头 + t[0] := r[i]; + r2 := _duplicate_r(r[i]['rNode']); + _adjust_r(r[i]['rNode'], 0, sPos - rSize); + _adjust_r(r2, sPos - rSize, txtLen); + return t; + End; + End + else Begin //w:del情况 + if rangeLength < 0 or (sPos <= rSize and sPos + rangeLength >= rSize + txtLen) then Begin //包含全部w:r + t[ length(t) ] := r[i]; + rSize += txtLen; + End + else if sPos >= txtLen + rSize then Begin //前 + rSize += txtLen; + End + else if sPos >= rSize and sPos < rSize + txtLen and sPos + rangeLength >= rSize + txtLen then Begin //一分为二,取尾部 + if sPos = rSize then Begin //正好整个run + t[ length(t) ] := r[i]; + End + else Begin //一分为二,取尾部 + r2 := _duplicate_r(r[i]['rNode']); + _adjust_r(r[i]['rNode'], 0, sPos - rSize); + _adjust_r(r2, sPos - rSize, txtLen); + tmp := r[i]; + tmp['rNode'] := r2; + tmp['rIndex'] := r[i]['rIndex'] + 1; + t[ length(t) ] := tmp; + End; + rSize += txtLen; + End + else if sPos + rangeLength <= rSize + txtLen then Begin + if sPos + rangeLength = rSize + txtLen then Begin //正好整个run + t[ length(t) ] := r[i]; + End + else if sPos <= rSize then Begin //一分为二,取头部 + t[ length(t) ] := r[i]; + r2 := _duplicate_r(r[i]['rNode']); + _adjust_r(r[i]['rNode'], 0, rangeLength - (rSize - sPos)); + _adjust_r(r2, rangeLength - (rSize - sPos), txtLen); + End + else Begin //一分为三,取中间 + r2 := _duplicate_r(r[i]['rNode']); + r3 := _duplicate_r(r2); + _adjust_r(r[i]['rNode'], 0, sPos - rSize); + _adjust_r(r2, sPos - rSize, rangeLength); + _adjust_r(r3, sPos - rSize + rangeLength, txtLen); + tmp := r[i]; + tmp['rNode'] := r2; + tmp['rIndex'] := r[i]['rIndex'] + 1; + t[0] := tmp; + End; + rSize += txtLen; + return t; + End + End; + End; + return t; + End; + + //复制w:r节点 + Function _duplicate_r(node); + Begin + data := node.Marshal(); + return node.Parent().InsertAfterChild(node, data[0]); + End; + + //调整w:r节点 + Function _adjust_r(node, sPos, rangeLength); + Begin + rSize := 0; + ePos := sPos + rangeLength; + delT := array(); + tNode := node.FirstChildElement('w:t'); + while ifObj(tNode) do Begin + txt := UTF8ToAnsi(tNode.GetText()); + txtLen := lengthW(txt); + if sPos >= rSize + txtLen then Begin //删除头部文字 + delT[cnt++] := tNode; + rSize += txtLen; + End + else if sPos >= rSize and sPos < rSize + txtLen and ePos <= rSize + txtLen then Begin //只取中间文字 + if sPos <> rSize or ePos <> rSize + txtLen then Begin //文字内容有变化 + mCnt := ePos - sPos; + if sPos = rSize then + nStr := leftstr(txt, mCnt); + else if ePos = rSize + txtLen then + nStr := rightstr(txt, mCnt); + else + nStr := midstr(txt, sPos - rSize + 1, mCnt); + tNode.SetValue(AnsiToUTF8(nStr)); + End; + rSize += txtLen; + End + else if sPos >= rSize and sPos < rSize + txtLen and ePos > rSize + txtLen then Begin //只取尾巴文字 + if sPos <> rSize then Begin //文字内容有变化 + mCnt := txtLen - (sPos - rSize); + nStr := rightstr(txt, mCnt); + tNode.SetValue(AnsiToUTF8(nStr)); + End; + End + else if sPos < rSize and ePos >= rSize + txtLen then Begin //取值范围 + rSize += txtLen; + End + else Begin //删除尾部文字 + delT[cnt++] := tNode; + End + rSize += txtLen; + tNode := tNode.NextElement('w:t'); + End; + + for i:=0 to length(delT)-1 do + node.DeleteChild(delT[i]); + End; + + node_; + name_:string; + pageNo_; //页码 + linePos_; //行位置 +End; + +Type TRevision = Class(DocObject, TRevisionImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Init(node); + End; + + Function Init(node); + Begin + node_ := node; + name_ := 'w:del'; + if ifObj(node_) then Begin + name_ := node_.GetName(); + paragraph_ := new TParagraph(node_); + End; + Date := class(TSXml).GetDatetimeStr(now()); + Class(TRevisionImpl).Create(nil, name_); + InitRootNode(node); + End; + + Property InsText read readInsText write writeInsText; + Function readInsText(); + Begin + return class(TSXml).Utf8ToCurCodePage(InsText_); + End; + + Function writeInsText(txt); + Begin + InsText_ := class(TSXml).CurCodePageToUtf8(txt); + End; + + ///修订类型 + ///返回:string, 删除:'del'、添加:'ins' + Function Act(); + Begin + return name_ = 'w:del' ? 'del' : 'ins'; + End; + + ///文字内容 + Function Text();override; + Begin + return paragraph_.Text(); + End; + + ///接受修订 + Function Accept(); + Begin + if name_ = 'w:del' then Begin + node_.Parent().DeleteChild(node_); + return nil; + End; + r := array(); + //w:ins + runs := paragraph_.GetRuns(); + node := node_; + for i:=0 to length(runs)-1 do Begin + rData := runs[i].node_.Marshal(); + node := node.Parent().InsertAfterChild(node, rData[0]);//接受修订,复制... + r[length(r)] := array('pNode':node.Parent(), 'pIndex':-1, 'rNode':node, 'rInde':-1); + End; + node_.Parent().DeleteChild(node_); + return r; + End; + + ///拒绝修订 + Function Reject(); + Begin + if name_ = 'w:ins' then Begin + node_.Parent().DeleteChild(node_); + return; + End; + //w:del + runs := paragraph_.GetRuns(); + node := node_; + for i:=0 to length(runs)-1 do Begin + rXml := string(runs[i].node_.Data()); + rXml := ReplaceStr(rXml, '', ''); + node := node.Parent().InsertAfterChild(node, rXml);//接受修订,复制... + End; + node_.Parent().DeleteChild(node_); + End; + + paragraph_; + CommentID:integer; + sPos:integer; + SelectLength:integer; + InsText_:string; +End; + +Type TDocComment = Class(TDocCommentImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + node_ := node; + name_ := 'w:comment'; + Date := class(TSXml).GetDatetimeStr(now()); + Class(TDocCommentImpl).Create(nil, name_); + InitRootNode(node); + End; + + ///批注文字内容 + Function Text(); + Begin + txt := ''; + rCnt := 0; + for i:= 0 to length(commentsArray_)-1 do Begin + if commentsArray_[i]['Name'] := 'w:r' then Begin + if rCnt and commentsArray_[i]['pIndex'] <> commentsArray_[i-1]['pIndex'] then + txt += '\n'; + run := new TRun(commentsArray_[i]['rNode']); + txt += run.Text(); + rCnt ++; + End; + End; + return txt; + End; + + ///删除批注 + Function Delete(); + Begin + commentsArray_[0]['pNode'].DeleteChild( commentsArray_[0]['rNode'] ); + cnt := length(commentsArray_) - 1; + r := commentsArray_[cnt]['rNode'].Next('w:r'); + if ifObj(r) then Begin + commentReference := r.FirstChildElement('w:commentReference'); + if ifObj(commentReference) then Begin + r.DeleteChild( commentReference ); + End; + End; + commentsArray_[cnt]['pNode'].DeleteChild( commentsArray_[cnt]['rNode'] ); + if not ifObj(r.FirstChildElement()) then Begin + r.Parent().DeleteChild( r ); + End; + End; + + CommentID:integer; + sPos:integer; + SelectLength:integer; + commentsArray_; +End; + +Type TDocComments = Class + Function Create(t); + Begin + commentsArray_ := t; + hash_ := sselect distinct ['ID'] from commentsArray_ where ['ID'] >= 0 end; + End; + + ///文档中全部的批注信息个数 + Function Count(); + Begin + return length(hash_); + End; + + ///文档中指定批注信息 + ///index:第index个批注信息 + ///返回:TDocComment对象 + Function Comment(index);overload; + Begin + if index < 0 or index >= length(hash_) then + return nil; + id := hash_[index]; + r := select thisrowindex as 'Index' from commentsArray_ where ['ID'] = id end; + if not istable(r) or length(r) <> 2 then + return nil; + t := select * from commentsArray_ where thisrowindex <= r[1]['Index'] and thisrowindex >= r[0]['Index'] end; + o := new TDocComment(); + o.commentsArray_ := t; + o.CommentID := t[0]['ID']; + return o; + End; + + hash_; + commentsArray_; +End; + +//w:pPr +// 'w:pStyle', 'w:keepNext', 'w:keepLines', 'w:pageBreakBefore', +// 'w:framePr', 'w:widowControl', 'w:numPr', 'w:suppressLineNumbers', +// 'w:pBdr', 'w:shd', 'w:tabs', 'w:suppressAutoHyphens', 'w:kinsoku', +// 'w:wordWrap', 'w:overflowPunct', 'w:topLinePunct', 'w:autoSpaceDE', +// 'w:autoSpaceDN', 'w:bidi', 'w:adjustRightInd', 'w:snapToGrid', +// 'w:spacing', 'w:ind', 'w:contextualSpacing', 'w:mirrorIndents', +// 'w:suppressOverlap', 'w:jc', 'w:textDirection', 'w:textAlignment', +// 'w:textboxTightWrap', 'w:outlineLvl', 'w:divId', 'w:cnfStyle', +// 'w:rPr', 'w:sectPr', 'w:pPrChange' + +//w:p +Type TWHyperLink = Class(TWHyperLinkImpl) + Function AddRun(txt, newLine); + Begin + o := new TRun(); + //o.Parent := self; + NewChildNode( array("field":"", "name":"w:r", "obj":o, "attrEx":"", "nodeType":"") ); + if txt then + o.SetText(txt); + if newLine then + o.Br.Type := ''; + return o; + End; +End; + +Type TParagraph = Class(DocObject, TParagraphImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Init(node); + End; + + Function Init(node); + Begin + node_ := node; + name_ := 'w:p'; + Class(TParagraphImpl).Create(nil, 'w:p'); + InitRootNode(node); + End; + + Function Root(); override; + Begin + return node_; + End; + + Property Format read readFormat; + Function readFormat(); + Begin + return pPr; + End; + + Property Font read readFont; + Function readFont(); + Begin + return pPr.rPr; + End; + + ///修改段落 + Function Apply(); override; + Begin + arr := Marshal(); + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + CopyRunFormat(false, nil); + End; + + ///修改段落内容 + ///返回:TRun对象 + Function SetText(str); + Begin + t := GetRuns(); + for i:=1 to length(t)-1 do Begin + node_.DeleteChild(t[i].node_); + End; + if length(t) then + rNode := t[0].node_; + else + rNode := node_.InsertEndChild('element', 'w:r'); + run := new TRun(rNode); + run.SetText(str); + return rNode; + End; + + ///制表位TTabStops对象 + ///返回:TTabStops对象 + // + // + // + // + Function TabStops(); + Begin + node := class(TSXml).GetNode(node_, 'w:pPr/w:tabs'); + if not ifObj(node) then + return nil; + return new TTabStops(node); + End; + + Function setParagraphText(rNode, tNode, txt); + Begin + if not ifObj(tNode) then Begin + tNode := rNode.FirstChildElement('w:t'); + if not ifObj(tNode) then + tNode := rNode.InsertFirstChild('element', 'w:t', txt); + End + else + tNode.SetValue(txt); + End; + + ///所有TRun对象列表 + ///返回:TRun对象列表 + Function GetRuns(); + Begin + t := array();//TRun Array + node := node_.FirstChildElement('w:r'); + while ifObj(node) do Begin + n := node; + name := node.GetName(); + node := node.NextElement('w:r'); + if name = 'w:r' then Begin + run := new TRun(n); + End + else if name = 'w:ins' then Begin + r := n.FirstChildElement('w:r'); + if not ifObj(r) then continue; + run := new TRun(r); + End + else + continue; + t[ length(t) ] := run; + End; + return t; + End; + + ///TRun对象 + ///返回:TRun对象 + Function GetRun(i); + Begin + runs := GetRuns(); + if i < 0 or i >= length(runs) then + return nil; + return runs[i]; + End; + + ///段落中添加内容 + ///返回:TRun对象 + Function AddRun(txt, newLine); + Begin + o := new TRun(); + //o.Parent := self; + NewChildNode( array("field":"", "name":"w:r", "obj":o, "attrEx":"", "nodeType":"") ); + if txt then + o.SetText(txt); + if newLine then + o.Br.Type := ''; + return o; + End; + + ///段落添加 + ///返回:TWHyperLink + Function AddHyperLink(); + Begin + o := new TWHyperLink(); + NewChildNode( array("field":"", "name":"w:r", "obj":o, "attrEx":"", "nodeType":"") ); + return o; + End; + + ///在段落对象后面追加TRun对象 + ///返回TRun对象 + Function AppendRun();overload; + Begin + node := node_.InsertEndChild('element','w:r'); + node.InsertFirstChild('element', 'w:rPr'); + return new TRun(node); + End; + + ///在段落某个TRun对象之后添加TRun对象 + ///run:TRun对象 + ///返回TRun对象 + Function AppendRun(run);overload; + Begin + node := run.NodeUri <> '' ? class(TSXml).GetNode(run.Root(), run.NodeUri) : run.Root(); + node := node_.InsertAfterChild(run.Root(), 'element','w:r'); + node.InsertFirstChild('element', 'w:rPr'); + return new TRun(node); + End; + + ///在段落对象开头添加TRun对象 + ///返回TRun对象 + Function PrependRun();overload; + Begin + node := node_.FirstChildElement('w:r'); + node := node_.InsertBeforeChild(node, 'element', 'w:r'); + node.InsertFirstChild('element', 'w:rPr'); + return new TRun(node); + End; + + ///在段落某个TRun对象之前添加TRun对象 + ///run:TRun对象 + ///返回TRun对象 + Function PrependRun(run);overload; + Begin + node := node_.InsertBeforeChild(run.Root(), 'element', 'w:r'); + node.InsertFirstChild('element', 'w:rPr'); + return new TRun(node); + End; + + ///段落中全部的修改标记(修订删除、修订插入) + ///返回:TRevision对象列表,array(TRevision...); + Function Revisions();overload; + Begin + return getDocumentObjects(node_, array('w:del', 'w:ins')); + End; + + ///段落指定修改标记(修订删除、修订插入) + ///index:第index个修改标记 + ///返回:TRevision对象 + Function Revisions(index);overload; + Begin + return getDocumentObject(node_, array('w:del', 'w:ins'), index); + End; + + ///段落中所有文本框 + ///返回:TTextBox对象数组 + Function TextBoxs();overload; + Begin + r := array(); + runs := GetRuns(); + for i:=0 to length(runs)-1 do Begin + node := class(TSXml).GetNode(runs[i].node_, 'mc:AlternateContent/mc:Fallback/w:pict/v:shape/v:textbox/w:txbxContent'); + if ifObj(node) then Begin + nodeEx := class(TSXml).GetNode(runs[i].node_, 'mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent'); + box := new TTextBox(node); + box.Init(node_, nodeEx); + r[length(r)] := box; + End + else Begin + node := class(TSXml).GetNode(runs[i].node_, 'w:pict/v:shape/v:textbox/w:txbxContent'); + if ifObj(node) then Begin + box := new TTextBox(node); + box.Init(node_, nil); + r[length(r)] := box; + End; + End; + End; + return r; + End; + + ///段落中指定文本框 + ///index:第index个文本框 + ///返回:TTextBox对象 + Function TextBoxs(index);overload; + Begin + r := TextBoxs(); + if index >= 0 and index < length(r) then + return r[index]; + return nil; + End; + + ///清除段落格式、字体格式 + Function ClearFormat(); + Begin + pPr := node_.FirstChildElement('w:pPr'); + //清除段落格式 + if ifObj(pPr) then + node_.DeleteChild(pPr); + //清除字体格式 + runs := GetRuns(); + for i:=0 to length(runs)-1 do Begin + runs[i].ClearFormat(); + End; + End; + + ///添加BookMark + ///返回:BookMark的名称,string + Function AddBookMark(bookMarkID); + Begin + pPr := node_.FirstChildElement('w:pPr'); + if ifObj(pPr) then + markStart := node_.InsertAfterChild(pPr, 'element', 'w:bookmarkStart'); + else + markStart := node_.InsertFirstChild('element', 'w:bookmarkStart'); + name := '_Toc' $ bookMarkID; + markStart.SetAttribute('w:name', name); + markStart.SetAttribute('w:id', bookMarkID); + markEnd := node_.InsertEndChild('element', 'w:bookmarkEnd'); + markEnd.SetAttribute('w:id', bookMarkID); + return name; + End; + + ///判断是否为空段落 + ///返回: bool + Function Empty(); + Begin + if ifObj(node_) then + begin + if ifObj(node_.FirstChildElement("w:r")) then return false; + sub_node := node_.FirstChildElement(); + if not ifObj(sub_node) then return true; + // 兼容wps + sub_node2 := sub_node.NextElement(); + if sub_node.GetName() = 'w:bookmarkStart' and ifObj(sub_node2) and sub_node2.GetName() = 'w:bookmarkEnd' then + return true; + // 兼容word + if sub_node.GetName() = 'w:pPr' and not ifObj(sub_node2) then + return true; + end + return false; + End; + + ///获取当前段落的上一个段落 + ///返回:TParagraph对象 + Function PrevParagraph(); + Begin + if ifObj(node_) then + begin + node := node_.PrevElement('w:p'); + return ifObj(node) ? new TParagraph(node) : nil; + end + End; + + Function CopyRunFormat(del, toRunNode); + Begin + rPr := class(TSXml).GetNode(node_, 'w:pPr/w:rPr'); + dom := ifObj(rPr) ? rPr.Marshal() : array(); + if ifObj(toRunNode) then Begin + _copyRunFormat(toRunNode, dom, del); + return; + End; + + //复制到所有run + runs := GetRuns(); + for i:=0 to length(runs)-1 do + _copyRunFormat(runs[i].node_, dom, del); + End; + + //不能复用TRun::CopyFontFormat(),该函数是完全替换字体属性 + //本函数是追加、修改字体属性 + Function _copyRunFormat(toRunNode, dom, del); + Begin + tNode := toRunNode.FirstChildElement('w:t'); + rPr2 := toRunNode.FirstChildElement('w:rPr'); + if del and ifObj(rPr2) then + rPr2.node_.DeleteChildren(); + else if ifObj(tNode) and not ifObj(rPr2) then + rPr2 := class(TSXml).GetNode(toRunNode, 'w:rPr', 'first'); + if istable(dom) and ifObj(rPr2) then + class(TSXml).UpdateNode(rPr2, dom[0]['attributes'], dom[0]['children']); + End; +End; + +//w:tabs +Type TTabStops = Class(DocObject, TTabStopsImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Class(TTabStopsImpl).Create(nil, 'w:tabs'); + tabArr := array(); + if ifObj(node) then Begin + parent_ := node.Parent(); + node_ := node; + n := node_.FirstChildElement('w:tab'); + while ifObj(n) do Begin + tab := new TTabStop(); + tabArr[ length(tabArr) ] := array("field":"TTabStop", "name":"w:tab", "obj":tab, "attrEx":"", "nodeType":"", "node":n); + n := n.NextElement(); + End; + Tabs := tabArr; + InitRootNode(node); + End; + End; + + Function Create(parentObj, name);overload; + Begin + Class(TTabStopsImpl).Create(parentObj, name); + tabArr := array(); + End; + + ///删除制表符 + ///ind:integer,索引 + Function Clear(ind); + Begin + if ind>=0 and ind < length(Tabs) then Begin + if ifObj(Tabs[i]['node']) then + node_.DeleteChild(Tabs[i]['node']); + Tabs := select * from Tabs where thisrowindex <> ind end; + End; + End; + + ///添加制表符 + ///ind:integer,索引 + ///tab:TTabStop对象 + Function Add(ind, tab); + Begin + a := array("field":"TTabStop", "name":"w:tab", "obj":tab, "attrEx":"", "nodeType":"", "node":nil); + if ind = 0 then Begin + if ifObj(node_) then + a['node'] := node_.InsertFirstChild('element', 'w:tab'); + Tabs := array(a) union Tabs; + End + else if ind < 0 or ind >= length(Tabs) then Begin + if ifObj(node_) then + a['node'] := node_.InsertEndChild('element', 'w:tab'); + Tabs union= array(a); + End + else Begin + node := Tabs[length(Tabs)-1]['node']; + if length(Tabs) and ifObj(node) then + a['node'] := node_.InsertAfterChild(node, 'element', 'w:tab'); + arr := Tabs[:ind-1,:]; + arr[ length(arr) ] := a; + b := Tabs[ind:,:]; + Tabs := arr union b; + End; + if ifObj(a['node']) then Begin + arr := tab.Marshal(); + class(TSXml).UpdateNode(a['node'], arr['attributes'], arr['children']); + End; + return tab; + End; + + ///获取制表符 + ///返回:TTabStop对象 + Function Get(ind); + Begin + if ind >= 0 or ind < length(Tabs) then + return Tabs[ind]['obj']; + return nil; + End; + + ///获取全部制表符列表 + ///返回:TTabStop对象列表,array(TTab...) + Function TabStops(); + Begin + return sselect ['obj'] from Tabs end; + End; + + ///刷新制表符 + Function Flush(); + Begin + if ifObj(node_) then Begin + for i:=0 to length(Tabs)-1 do Begin + arr := Tabs[i]['obj'].Marshal(); + class(TSXml).UpdateNode(Tabs[i]['node'], arr['attributes'], arr['children']); + End; + End; + End; +End; + +//w:r +Type TRun = Class(DocObject, TRunImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Init(node); + End; + + Function Create(pNode, name);overload; + Begin + Class(TRunImpl).Create(nil, 'w:r'); + End; + + Function Init(node); + Begin + node_ := node; + name_ := 'w:r'; + Class(TRunImpl).Create(nil, 'w:r'); + InitRootNode(node); + End; + + Property Font read readFont; + Function readFont(); + Begin + return rPr; + End; + + ///应用格式 + Function Apply(); override; + Begin + arr := Marshal(); + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + End; + + ///添加tab + Function AddTab(); + Begin + n := node_.InsertFirstChild('element', 'w:tab'); + End; + + ///添加文字 + ///[isUtf8]:可选参数,当前字符集是否utf8,缺省false + Function AddText(txt, isUtf8); + Begin + str := txt; + if not isUtf8 and not class(TSXml).IsUtf8() then + str := class(TSXml).CurCodePageToUtf8(txt); + if ifObj(node_) then Begin + _insertText(str, false); + return; + End; + lines := str2array(str,'\n'); + T := lines[0]; + if _preserve(T) then + Space := 'preserve'; + for i:=1 to length(lines)-1 do Begin + NewChildNode( array("field":"", "name":"w:br", "obj":1, "attrEx":"", "nodeType":"empty") ); + NewChildNode( array("field":"", "name":"w:t", "obj":lines[i], "attrEx":"", "nodeType":"pcdata") ); + if _preserve(lines[i]) then + NewChildNode( array("field":"", "name":"w:t", "obj":'preserve', "attrEx":"xml:space", "nodeType":"") ); + End; + End; + + ///修改文字 + ///[isUtf8]:可选参数,当前字符集是否utf8,缺省false + Function SetText(txt, isUtf8); + Begin + str := txt; + if not isUtf8 and not class(TSXml).IsUtf8() then + str := class(TSXml).CurCodePageToUtf8(txt); + if ifObj(node_) then Begin + ClearText();//删除原来文字 + _insertText(str, false);//添加文字 + return; + End; + ExtNodes := array(); + T := nil; + AddText(str, true); + End; + + Function _insertText(txt, first); + Begin + lines := str2array(txt,'\n'); + for i:=0 to length(lines)-1 do Begin + t := TrimRight(lines[i]); + if i=0 then Begin + if first then + tNode := node_.InsertFirstChild('element', 'w:t', t); + else + tNode := node_.InsertEndChild('element', 'w:t', t); + End + else Begin + tNode := node_.InsertAfterChild(tNode, 'element', 'w:br');//换行符号 + tNode := node_.InsertAfterChild(tNode, 'element', 'w:t', t); + End; + End; + End; + + ///文字内容 + Function Text();override; + Begin + txt := ''; + tNode := node_.FirstChildElement(); + while ifObj(tNode) do Begin + name := tNode.GetName(); + if name = 'w:t' or name = 'w:delText' then + txt += tNode.GetText(); + //if name = 'w:br' then + // txt += '\n'; + tNode := tNode.NextElement(); + End; + if not class(TSXml).IsUtf8() then + return class(TSXml).Utf8ToCurCodePage(txt); + return txt; + End; + + ///清除字体格式 + Function ClearFormat(); + Begin + rpr_node := node_.FirstChildElement('w:rPr'); + if ifObj(rpr_node) then + node_.DeleteChild(rpr_node); + End; + + Function CopyFontFormat(fromRun); + Begin + ClearFormat(); + rpr_node := fromRun.node_.FirstChildElement('w:rPr'); + if not ifObj(rpr_node) then + return; + + data := rpr_node.Marshal(); + node_.InsertFirstChild(data[0]); + End; + + ///清除全部文字内容 + Function ClearText(); + Begin + if ifObj(node_) then Begin + n := node_.FirstChildElement('w:t'); + while ifObj(n) do Begin + next := n.NextElement('w:t'); + node_.DeleteChild(n); + n := next; + End; + End; + End; + +End; + +Type TPicture = Class(DocObject, TPictureImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Init(node); + End; + + Function Init(node); + Begin + node_ := node; + name_ := 'w:p'; + Width := 0.; + Height := Width; + Class(TPictureImpl).Create(nil, 'w:p'); + InitRootNode(node); + End; + + Property Format read readFormat; + Function readFormat(); + Begin + return Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr; + End; + + ///修改图片格式 + ///[docx]:当前文档对象,为空指当前文档 + Function Apply(docx); override; + Begin + document := docx; + if not ifObj(document) then Begin + document := TOfficeApi().GetDocument(); + if not ifObj(document) then + return; + End; + arr := Marshal(); + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + if ifBinary(Image) then Begin //修改图片内容 + node := class(TSXml).GetNode(node_,'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip'); + if ifObj(node) then + rid := node.GetAttribute('r:embed'); + xml := document.Zip().Get('word/_rels/document.xml.rels'); + picFileName := class(TSXml).FindRelationshipTarget(xml, rid); + if ifstring(picFileName) then Begin + pic := document.Zip().Get('word/' + picFileName); + if ifObj(pic) then + pic.Data := Image; + End; + End; + End; + + Function ScaledDimensions(image); + Begin + ETU := 360045;//1cm单位 + maxX := 17.0;//水平方向17cm + maxY := 23.0;//垂直方向23cm + imageW := image.Width() / 28.346 * ETU; + imageH := image.Height() / 28.346 * ETU; + if Width <= 0 and Height <= 0 then Begin //图像缺省大小 + widthVal := imageW; + heightVal := imageH; + End + else Begin //用户设置了图片尺寸 + widthVal := ETU * Width; + heightVal := ETU * Height; + if Width <= 0 and imageH and imageW then Begin //按照图片比例自动缩放 + scaling_factor := imageW / imageH; + widthVal := round(heightVal * scaling_factor); + End; + + if Height <= 0 and imageH and imageW then Begin //按照图片比例自动缩放 + scaling_factor := imageW / imageH; + heightVal := round(widthVal / scaling_factor); + End; + End; + //缺省大小(用户没有设置尺寸,同时TSImage也没有识别图片尺寸) + if widthVal = 0 and heightVal = 0 then + widthVal := 15 * ETU; + if widthVal = 0 then + widthVal := heightVal * 2; + if heightVal = 0 then + heightVal := widthVal / 3; + + //缩放 + ratio := 1; + if widthVal > maxX * ETU then + ratio := maxX * ETU / widthVal; + if heightVal > maxY * ETU then Begin + r2 := maxY * ETU / heightVal; + if r2 < ratio then + ratio := r2; + End; + if ratio < 1 then Begin + heightVal *= ratio; + widthVal *= ratio; + End; + //println('w={}-{},maxx={}, h={}-{},maxh={},ratio={}',integer(imageW),integer(widthVal),15 * ETU, integer(imageH),integer(heightVal),23 * ETU,ratio); + return array(integer(widthVal), integer(heightVal)); + End; + + Image;//图片内容(Binary) + Descr; + Width;//厘米 + Height;//厘米 +End; + +Type TChart = Class(TChartImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Class(TChartImpl).Create(nil, 'w:p'); + pNode := node; + self.C := true; + InitRootNode(node); + End; + + Function Init(docx, node, cNode); + Begin + pNode := node; + if not ifObj(cNode) then + return; + IsWord_ := docx.IsWord(); + rId := cNode.GetAttribute('r:id'); + relsObj := docx.Zip().Get('word/_rels/document.xml.rels'); + Target := class(TSXml).FindRelationshipTarget(relsObj, rId); + if ifNil(Target) then + return; + chartFileName := getChartFileName(Target); + xmlObj := docx.Zip().Get(chartFileName); + if not ifObj(xmlObj) then + return; + plotAreaNode := class(TSXml).GetNode(xmlObj, 'c:chartSpace/c:chart/c:plotArea'); + if ifObj(plotAreaNode) then Begin + child := plotAreaNode.FirstChildElement(); + while ifObj(child) do Begin + nodename := child.GetName(); + if rightstr(nodename,5) = 'Chart' then Begin + if leftstr(nodename,2) = 'c:' then + self.C := true; + ChartNode := child; + break; + End; + child := child.NextElement(); + End; + End; + End; + + Function Serialize(isWord); + Begin + Plotarea := TOfficeObj('TPlotarea'); + Plotarea.Layout := true; + isWord_ := isWord; + Type := lowercase(Type); + case Type of + 'area','areastacked','areapercentstacked','area3d','area3dstacked','area3dpercentstacked','bar','barstacked','barpercentstacked', + 'bar3dclustered','bar3dstacked','bar3dpercentstacked','bar3dconeclustered','bar3dconestacked','bar3dconepercentstacked', + 'bar3dpyramidclustered','bar3dpyramidstacked','bar3dpyramidpercentstacked','bar3dcylinderclustered','bar3dcylinderstacked', + 'bar3dcylinderpercentstacked','col','colstacked','colpercentstacked','col3d','col3dclustered','col3dstacked','col3dpercentstacked', + 'col3dcone','col3dconeclustered','col3dconestacked','col3dconepercentstacked','col3dpyramid','col3dpyramidclustered', + 'col3dpyramidstacked','col3dpyramidpercentstacked','col3dcylinder','col3dcylinderclustered','col3dcylinderstacked', + 'col3dcylinderpercentstacked','bubble','bubble3d': + drawBaseChart(Plotarea); + 'doughnut': + Begin + drawExtChart(Plotarea, 'c:doughnutChart'); + Plotarea.chart.HoleSize := 75; + End + 'line': + drawLineChart(Plotarea); + 'pie3d': + drawExtChart(Plotarea, 'c:pie3DChart'); + 'pie': + drawExtChart(Plotarea, 'c:pieChart'); + 'pieofpiechart': + Begin + drawExtChart(Plotarea, 'ofPieChart'); + Plotarea.chart.OfPieType := 'pie'; + End + 'barofpiechart': + Begin + drawExtChart(Plotarea, 'c:ofPieChart'); + Plotarea.chart.OfPieType := 'bar'; + End + 'radar': + drawRadarChart(Plotarea); + 'scatter': + drawScatterChart(Plotarea); + 'surface3d','wireframesurface3d': + drawSurface3DChart(Plotarea, 'c:surface3DChart'); + 'contour','wireframecontour': + drawSurface3DChart(Plotarea, 'c:surfaceChart'); + End; + Plotarea.SpPr.noFill := true; + Plotarea.SpPr.Ln.noFill := true; + Plotarea.SpPr.EffectLst := true; + End; + + ///添加图表Series数据 + Function AddSeries(Name, Categories, Value); + Begin + SerName := name; + catArr := Categories; + if not class(TSXml).IsUtf8() then Begin + if name and ifstring(name) then + SerName := class(TSXml).CurCodePageToUtf8(name); + if ifstring(catArr) then + catArr := class(TSXml).CurCodePageToUtf8(catArr); + else if istable(catArr) then Begin + for i:=0 to length(catArr)-1 do Begin + if ifstring(catArr[i]) then + catArr[i] := class(TSXml).CurCodePageToUtf8(catArr[i]); + End; + End; + End; + + Series union= array(("Name":SerName,"Categories":catArr,"Values":Value)); + return length(Series); + End; + + ///清除图表Series数据 + Function ClearSeries(); + Begin + Series := array(); + End; + + ///删除图表Series数据 + Function RemoveSeries(i); + Begin + cnt := length(Series); + if i < 0 or i >= cnt then + return length(Series); + + tmp := Series[:i-1,:]; + tmp union= Series[i+1:,:]; + Series := tmp; + return length(Series); + End; + + Function NewExcelFile(); + Begin + Excel := new TSExcelFile(); + [err, errmsg] := Excel.NewFile(); + if err then + Excel := nil; + End; + + ///更新图表 + Function Apply(docx); + Begin + if not ifObj(ChartNode) then + return; + if ifstring(Title) and Title <> '' then + UpdateTitle(class(TSXml).CurCodePageToUtf8(Title)); + //不同的图表,数据区较复杂 + if not istable(Series) then return; + ser := self.C ? 'c:ser' : 'ser'; + serNode := ChartNode.FirstChildElement(ser); + if not ifObj(serNode) then return;//没有缺省数据 + //存在Excel扩展数据文件 + node := xmlObj.FirstChildElement('c:chartSpace').FirstChildElement('c:externalData'); + if ifObj(node) then Begin + rId := node.GetAttribute('r:id'); + fName := ExtractFileName(chartFileName); + rels := 'word/charts/_rels/' + fName + '.rels'; + chartId := leftstr(fName, length(fName) - 4); + chartId := rightstr(chartId, length(chartId) - 5); + relsObj := docx.Zip().Get(rels); + if ifObj(relsObj) then Begin + target := class(TSXml).FindRelationshipTarget(relsObj, rId);//../embeddings/Workbook2.xlsx + excelFileName := ReplaceStr(target, '..','word'); + excelObj := docx.Zip().Get(excelFileName); + if ifObj(excelObj) then + NewExcelFile(); + End; + End; + + //更新数据区 + dom := serNode.Marshal(); + for i:=0 to length(Series)-1 do Begin + if i then + serNode := serNode.InsertAfterChild(serNode, dom[0]); + removeOldSer(serNode); + ser := TOfficeObj('TSer'); + ser.IDx := i; + ser.Ord := i; + setTx(ser.Tx.StrRef, Series[i]['Name'], i); + n := serNode.FirstChildElement('c:cat'); + if ifObj(n) then Begin + _setCat(ser.Cat, i); + _setVal(ser.Val, i); + End; + + n := serNode.FirstChildElement('c:xVal'); + if ifObj(n) then Begin + _setCat(ser.XVal, i); + _setVal(ser.YVal, i); + End; + updData := ser.Marshal(); + class(TSXml).UpdateNode(serNode, updData['attributes'], updData['children']); + End; + + //删除多余的 + node := serNode.NextElement(ser); + while ifObj(node) do Begin + ChartNode.DeleteChild(node); + node := serNode.NextElement(ser); + End; + + //修改内嵌的excel文件 + AddExcelFile(docx, xmlObj, chartId); + End; + + Function removeOldSer(node); + Begin + task := array('c:tx','c:cat','c:val','c:xVal','c:xYal'); + for i:=0 to length(task)-1 do begin + n := node.FirstChildElement(task[i]); + if ifObj(n) then + n.DeleteChildren(); + End; + End; + + Function AddExcelFile(docx, chartXml, chartId); + Begin + //内嵌excel数据文件 + if not ifObj(Excel) then + return; + [err, data] := Excel.Zip().Save2Mem(); + if err then + return; + rId := 'rId1'; + workBook := 'embeddings/Workbook1.xlsx'; + fileCnt := 1 + vselect countof( ['FileName'] ) from docx.Zip().Files() where AnsiStartsText('word/embeddings/Workbook', ['FileName']) end; + ctXml := docx.Zip().Get('[Content_Types].xml'); + class(TSXml).AddDefaultContentType(ctXml, 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + externalDataNode := chartXml.FirstChildElement('c:chartSpace').FirstChildElement('c:externalData'); + if not ifObj(externalDataNode) then + chartXml.FirstChildElement('c:chartSpace').InsertEndChild(''); + else Begin + rId := externalDataNode.GetAttribute('r:id'); + End; + rels := 'word/charts/_rels/chart' $ chartId $ '.xml.rels'; + relsObj := docx.Zip().Get(rels); + if not ifObj(relsObj) then Begin + rId := 'rId1'; + xmlStr := ' + + +'; + docx.Zip().Add(rels, xmlStr); + if fileCnt > 1 then Begin + workBook := 'embeddings/Workbook' $ fileCnt $ '.xlsx'; + relsObj := docx.Zip().Get(rels); + node := relsObj.FirstChildElement('Relationships').FirstChildElement('Relationship'); + node.SetAttribute('Target', '../' + workBook); + End; + End + else Begin + target := class(TSXml).FindRelationshipTarget(relsObj, rId); + if ifNil(target) then Begin + [maxRid, tg, id] := class(TSXml).FindRelationshipRid(relsObj,''); + if fileCnt > 1 then + workBook := 'embeddings/Workbook' $ fileCnt $ '.xlsx'; + maxRid ++; + class(TSXml).AddRelationshipRid(relsObj, '../' + workBook, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package', 'rId' $ maxRid, nil); + End + else + workBook := ReplaceStr(target, '../', ''); + End; + xlsx := docx.Zip().Get('word/' + workBook); + if ifObj(xlsx) then + xlsx.Data := data; //更新xlsx文件 + else + docx.Zip().Add('word/' + workBook, data); //添加xlsx文件 + End; + + ///修改图表标题 + Function UpdateTitle(t); + Begin + task := array('c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t', 'pcdata', t); + class(TSXml).SetNodeValue(ChartNode.Root(), task); + End; + + ///显示数据表 + ///b:bool型,是否显示数据表 + Function ShowDataTable(b); + Begin + if not ifObj(plotAreaNode) then + return; + node := plotAreaNode.FirstChildElement('c:dTable'); + if ifObj(node) then + plotAreaNode.DeleteChild(node); + if not b then + return; + xmlStr := ' + + + + + + + + + + + + + + + + + + + + + '; + plotAreaNode.InsertEndChild(xmlStr); + End; +private + Function getChartFileName(f); + Begin + if leftstr(f,5) = 'word/' then + return f; + if leftstr(f,3) = '../' then + return 'word/' + f[4:]; + if f[1] = '/' then + return f[2:]; + if leftstr(f,7) = 'charts/' then + return 'word/' + f; + return f; + End; + + Function updateValue(task); + Begin + for i:=0 to length(task)-1 do Begin + if not C then + task[i][0] := ReplaceStr(task[i][0], 'c:', ''); + class(TSXml).SetNodeValue(xmlObj_, task[i]); + End; + End; + + Function getLegendPosition(t); + Begin + m := array("bottom": "b", + "left": "l", + "right": "r", + "top": "t", + "top_right": "tr"); + return m[t]; + End; + + Function drawSurface3DChart(o, name); + Begin + o.chart.NodeName := name; + setChartSer(o); + o.chart.Axid := 754001152; + o.chart.Axid2 := 753999904; + o.chart.Axid3 := 832256642; + setCatAx(o.CatAx); + setValAx(o.ValAx); + setSerAx(o.SerAx); + if Type in array( 'wireframesurface3d', 'wireframecontour' ) then + o.chart.Wireframe := true; + End; + + Function drawScatterChart(o); + Begin + o.chart.NodeName := 'c:scatterChart'; + o.chart.ScatterStyle := 'smoothMarker'; + o.chart.VaryColors := false; + setChartSer(o); + setDLbls(o.chart.DLbls); + o.chart.Axid := 754001152; + o.chart.Axid2 := 753999904; + setCatAx(o.CatAx); + setValAx(o.ValAx); + End; + + Function drawRadarChart(o); + Begin + o.chart.NodeName := 'c:radarChart'; + o.chart.RadarStyle := 'marker'; + o.chart.VaryColors := false; + setChartSer(o); + setDLbls(o.chart.DLbls); + o.chart.Axid := 754001152; + o.chart.Axid2 := 753999904; + setCatAx(o.CatAx); + setValAx(o.ValAx); + End; + + Function drawExtChart(o, name); + Begin + o.chart.NodeName := name; + o.chart.VaryColors := VaryColors; + setChartSer(o); + setDLbls(o.chart.DLbls); + End; + + Function drawLineChart(o); + Begin + o.chart.NodeName := 'c:lineChart'; + o.chart.Grouping := getGrouping(Type); + o.chart.VaryColors := false; + setChartSer(o); + setDLbls(o.chart.DLbls); + o.chart.Smooth := false; + o.chart.Axid := 754001152; + o.chart.Axid2 := 753999904; + setCatAx(o.CatAx); + setValAx(o.ValAx); + End; + + Function drawBaseChart(o); + Begin + o.chart.BarDir := getBarDir(Type); + o.chart.Grouping := getGrouping(Type); + o.chart.VaryColors := VaryColors; + o.chart.Overlap := getVaryColors(Type); + o.chart.Axid := 754001152; + o.chart.Axid2 := 753999904; + o.chart.NodeName := getChartName(Type); + setChartSer(o); + o.chart.Shape := getSharp(Type); + setDLbls(o.chart.DLbls); + setCatAx(o.CatAx); + setValAx(o.ValAx); + End; + + Function setSerAx(SerAx); + Begin + SerAx.AxID := 832256642; + SerAx.Scaling.Max := YAxis.Max; + SerAx.Scaling.Min := YAxis.Min; + SerAx.Scaling.Orientation := YAxis.ReverseOrder ? 'maxMin' : 'minMax'; + SerAx.Del := YAxis.None; + SerAx.AxPos := XAxis.ReverseOrder ? 't' : 'b'; + SerAx.TickLblPos := 'nextTo'; + drawPlotAreaSpPr(SerAx.SpPr); + drawPlotAreaTxPr(SerAx.TxPr); + SerAx.CrossAx := 753999904; + End; + + Function setCatAx(CatAx); + Begin + CatAx.AxID := 754001152; + CatAx.Scaling.Max := XAxis.Max; + CatAx.Scaling.Min := XAxis.Min; + CatAx.Scaling.Orientation := XAxis.ReverseOrder ? 'maxMin' : 'minMax'; + CatAx.Del := 0;//XAxis.None; + CatAx.AxPos := XAxis.ReverseOrder ? 't' : 'b'; + CatAx.NumFmt.FormatCode := 'General'; + CatAx.NumFmt.SourceLinked := true; + CatAx.MajorTickMark := 'none'; + CatAx.MinorTickMark := 'none'; + CatAx.TickLblPos := 'nextTo'; + drawPlotAreaSpPr(CatAx.SpPr); + drawPlotAreaTxPr(CatAx.TxPr); + CatAx.CrossAx := 753999904; + CatAx.Crosses := 'autoZero'; + CatAx.Auto := true; + CatAx.LblAlgn := 'ctr'; + CatAx.LblOffset := 100; + CatAx.NoMultiLvlLbl := false; + if XAxis.MajorGridlines then + drawPlotAreaSpPr(CatAx.MajorGridlines.SpPr); + if XAxis.MinorGridlines then + drawPlotAreaSpPr(CatAx.MinorGridlines.SpPr); + if XAxis.TickLabelSkip then + CatAx.TickLabelSkip := XAxis.TickLabelSkip; + End; + + Function setValAx(ValAx); + Begin + ValAx.AxID := 753999904; + ValAx.Scaling.Max := YAxis.Max; + ValAx.Scaling.Min := YAxis.Min; + if ifint(YAxis.LogBase) and YAxis.LogBase >= 2 and YAxis.LogBase <= 1000 then + ValAx.Scaling.LogBase := YAxis.LogBase; + ValAx.Scaling.Orientation := YAxis.ReverseOrder ? 'maxMin' : 'minMax'; + ValAx.Del := YAxis.None; + ValAx.AxPos := YAxis.ReverseOrder ? 'r' : 'l'; + ValAx.NumFmt.FormatCode := chartValAxNumFmtFormatCode(Type); + ValAx.NumFmt.SourceLinked := true; + ValAx.MajorTickMark := 'none'; + ValAx.MinorTickMark := 'none'; + ValAx.TickLblPos := 'nextTo'; + drawPlotAreaSpPr(ValAx.SpPr); + drawPlotAreaTxPr(ValAx.TxPr); + ValAx.CrossAx := 754001152; + ValAx.Crosses := 'autoZero'; + ValAx.CrossBetween := chartValAxCrossBetween(Type); + if XAxis.MajorGridlines then + drawPlotAreaSpPr(ValAx.MajorGridlines.SpPr); + if XAxis.MinorGridlines then + drawPlotAreaSpPr(ValAx.MinorGridlines.SpPr); + ValAx.MajorUnit := YAxis.MajorUnit; + if Type in array('contour', 'wireframecontour') then + ValAx.TickLblPos := 'none'; + End; + + Function chartValAxCrossBetween(t); + Begin + m := array( + 'area': 'midCat', + 'areastacked': 'midCat', + 'areapercentstacked': 'midCat', + 'area3d': 'midCat', + 'area3dstacked': 'midCat', + 'area3dpercentstacked': 'midCat', + 'bar': 'between', + 'barstacked': 'between', + 'barpercentstacked': 'between', + 'bar3dclustered': 'between', + 'bar3dstacked': 'between', + 'bar3dpercentstacked': 'between', + 'bar3dconeclustered': 'between', + 'bar3dconestacked': 'between', + 'bar3dconepercentstacked': 'between', + 'bar3dpyramidclustered': 'between', + 'bar3dpyramidstacked': 'between', + 'bar3dpyramidpercentstacked': 'between', + 'bar3dcylinderclustered': 'between', + 'bar3dcylinderstacked': 'between', + 'bar3dcylinderpercentstacked': 'between', + 'col': 'between', + 'colstacked': 'between', + 'colpercentstacked': 'between', + 'col3d': 'between', + 'col3dclustered': 'between', + 'col3dstacked': 'between', + 'col3dpercentstacked': 'between', + 'col3dcone': 'between', + 'col3dconeclustered': 'between', + 'col3dconestacked': 'between', + 'col3dconepercentstacked': 'between', + 'col3dpyramid': 'between', + 'col3dpyramidclustered': 'between', + 'col3dpyramidstacked': 'between', + 'col3dpyramidpercentstacked': 'between', + 'col3dcylinder': 'between', + 'col3dcylinderclustered': 'between', + 'col3dcylinderstacked': 'between', + 'col3dcylinderpercentstacked': 'between', + 'doughnut': 'between', + 'line': 'between', + 'pie': 'between', + 'pie3d': 'between', + 'pieofpiechart': 'between', + 'barofpiechart': 'between', + 'radar': 'between', + 'scatter': 'between', + 'surface3d': 'midCat', + 'wireframesurface3d': 'midCat', + 'contour': 'midCat', + 'wireframecontour': 'midCat', + 'bubble': 'midCat', + 'bubble3d': 'midCat'); + return m[t]; + End; + + Function chartValAxNumFmtFormatCode(t); + Begin + m := array( + 'area': 'General', + 'areastacked': 'General', + 'areapercentstacked': '0%', + 'area3d': 'General', + 'area3dstacked': 'General', + 'area3dpercentstacked': '0%', + 'bar': 'General', + 'barstacked': 'General', + 'barpercentstacked': '0%', + 'bar3dclustered': 'General', + 'bar3dstacked': 'General', + 'bar3dpercentstacked': '0%', + 'bar3dconeclustered': 'General', + 'bar3dconestacked': 'General', + 'bar3dconepercentstacked': '0%', + 'bar3dpyramidclustered': 'General', + 'bar3dpyramidstacked': 'General', + 'bar3dpyramidpercentstacked': '0%', + 'bar3dcylinderclustered': 'General', + 'bar3dcylinderstacked': 'General', + 'bar3dcylinderpercentstacked': '0%', + 'col': 'General', + 'colstacked': 'General', + 'colpercentstacked': '0%', + 'col3d': 'General', + 'col3dclustered': 'General', + 'col3dstacked': 'General', + 'col3dpercentstacked': '0%', + 'col3dcone': 'General', + 'col3dconeclustered': 'General', + 'col3dconestacked': 'General', + 'col3dconepercentstacked': '0%', + 'col3dpyramid': 'General', + 'col3dpyramidclustered': 'General', + 'col3dpyramidstacked': 'General', + 'col3dpyramidpercentstacked': '0%', + 'col3dcylinder': 'General', + 'col3dcylinderclustered': 'General', + 'col3dcylinderstacked': 'General', + 'col3dcylinderpercentstacked': '0%', + 'doughnut': 'General', + 'line': 'General', + 'pie': 'General', + 'pie3d': 'General', + 'pieofpiechart': 'General', + 'barofpiechart': 'General', + 'radar': 'General', + 'scatter': 'General', + 'surface3d': 'General', + 'wireframesurface3d': 'General', + 'contour': 'General', + 'wireframecontour': 'General', + 'bubble': 'General', + 'bubble3d': 'General'); + return m[t]; + End; + + Function drawPlotAreaTxPr(TxPr); + Begin + TxPr.BodyPr.Rot := -60000000; + TxPr.BodyPr.SpcFirstLastPara := true; + TxPr.BodyPr.VertOverflow := 'ellipsis'; + TxPr.BodyPr.Vert := 'horz'; + TxPr.BodyPr.Wrap := 'square'; + TxPr.BodyPr.Anchor := 'ctr'; + TxPr.BodyPr.AnchorCtr := true; + TxPr.P.PPr.DefRPr.Sz := 900; + TxPr.P.PPr.DefRPr.Bold := false; + TxPr.P.PPr.DefRPr.Italic := false; + TxPr.P.PPr.DefRPr.U := 'none'; + TxPr.P.PPr.DefRPr.Strike := 'noStrike'; + TxPr.P.PPr.DefRPr.Kern := 1200; + TxPr.P.PPr.DefRPr.Baseline := 0; + TxPr.P.PPr.DefRPr.SolidFill.SchemeClr.Val := 'tx1'; + TxPr.P.PPr.DefRPr.SolidFill.SchemeClr.LumMod := 15000; + TxPr.P.PPr.DefRPr.SolidFill.SchemeClr.LumOff := 85000; + TxPr.P.PPr.DefRPr.Latin.Typeface := '+mn-lt'; + TxPr.P.PPr.DefRPr.Ea.Typeface := '+mn-ea'; + TxPr.P.PPr.DefRPr.Cs.Typeface := '+mn-cs'; + TxPr.P.EndParaRPr.Lang := 'en-US'; + End; + + Function drawPlotAreaSpPr(SpPr); + Begin + SpPr.Ln.W := 9525; + SpPr.Ln.Cap := 'flat'; + SpPr.Ln.Cmpd := 'sng'; + SpPr.Ln.Algn := 'ctr'; + SpPr.Ln.SolidFill.SchemeClr.Val := 'tx1'; + SpPr.Ln.SolidFill.SchemeClr.LumMod := 15000; + SpPr.Ln.SolidFill.SchemeClr.LumOff := 85000; + End; + + Function setChartSer(o); + Begin + SerArr := array(); + for i:=0 to length(Series)-1 do Begin + ser := TOfficeObj('TSer'); + SerArr union= array(('name':'c:ser','obj':ser,'attrEx':'','nodeType':'','attrName':'')); + ser.IDx := i + Ord; + ser.Ord := i + Ord; + setTx(ser.Tx.StrRef, Series[i]['Name'], i); + setSpPr(ser.SpPr, i); + setMarker(ser.Marker, i); + setDpt(ser, i); + //setDLbls(ser.DLbls); + //ser.Dlbls.Del := 1; + //ser.InvertIfNegative := false; + setCat(ser.Cat, i); + setVal(ser.Val, i); + setXVal(ser.XVal, i); + setYVal(ser.YVal, i); + setBubbleSize(ser.BubbleSize, i); + setBubble3D(ser, i); + End; + o.chart.Ser := SerArr; + End; + + Function _setExcelCellVal(cell, v); + Begin + //v is utf8 + if ifObj(Excel) then Begin + Excel.SetCellValue('Sheet1', cell, class(TSXml).Utf8ToCurCodePage(v)); + End; + End; + + Function setTx(strRef, name, i); + Begin + if not IsWord_ then Begin + strRef.F := name; + return; + End; + [err, col] := ColumnNumberToName(i + 2); + strRef.F := 'Sheet1!$' $ col $ '$1'; + strRef.strCache.ptCount := 1; + strRef.strCache.pt.IDx := 0; + strRef.strCache.pt.V := name; + _setExcelCellVal(col $ '1', name); + End; + + Function setBubble3D(ser, i); + Begin + if Type <> 'bubble3d' then return; + ser.Bubble3D := true; + End; + + Function setBubbleSize(BubbleSize, i); + Begin + if not (Type in array('bubble', 'bubble3d')) then return; + _setVal(BubbleSize, i); + End; + + Function setYVal(Val, i); + Begin + if not (Type in array('scatter', 'bubble', 'bubble3d')) then return; + _setVal(Val, i); + End; + + Function setXVal(xVal, i); + Begin + if not (Type in array('scatter')) then return; + _setCat(xVal, i); + End; + + Function setVal(Val, ind); + Begin + if Type in array('scatter', 'bubble', 'bubble3d') then return; + _setVal(Val, ind); + End; + + Function _setVal(Val, ind); + Begin + data := Series[ind]['Values']; + if ifstring(data) then + Val.NumRef.F := data; //excel图表(Sheet1!$C$2:$C$6) + else if istable(data) then Begin //word 图表 + cnt := length(data); + //[err, axis] := ColumnNumberToName(2 * ind + 2); + [err, axis] := ColumnNumberToName(ind + 2); + Val.NumRef.F := format('Sheet1!$%s$2:$%s$%d', axis, axis, cnt+1); + Val.NumRef.NumCache.PtCount := cnt; + Val.NumRef.NumCache.formatCode := 'General'; + for i:=0 to cnt-1 do Begin + Tpt := TOfficeObj('Tpt'); + Tpt.IDx := i; + Tpt.V := data[i]; + //[err,cell] := CoordinatesToCellName(2*ind+2, i+2); + [err,cell] := CoordinatesToCellName(ind+2, i+2); + _setExcelCellVal(cell, data[i]); + Val.NumRef.NumCache.NewChildNode( array("field":"", "name":"c:pt", "obj":Tpt, "attrEx":"", "nodeType":"") ); + End; + End; + End; + + Function setCat(Cat, ind); + Begin + if Type in array('scatter', 'bubble', 'bubble3d') then return; + _setCat(Cat, ind); + End; + + Function _setCat(Cat, ind); + Begin + Categories := Series[ind]['Categories']; + if ifstring(Categories) then + cat.StrRef.F := Categories; //excel图表(Sheet1!$A$2:$A$6) + else if istable(Categories) then Begin //word 图表 + cnt := length(Categories); + //[err, axis] := ColumnNumberToName(2 * ind + 1); + cat.StrRef.F := format('Sheet1!$A$2:$A$%d', cnt+1); + cat.StrRef.StrCache.PtCount := cnt; + for i:=0 to cnt-1 do Begin + Tpt := TOfficeObj('Tpt'); + Tpt.IDx := i; + Tpt.V := Categories[i]; + [err,cell] := CoordinatesToCellName(2*ind+1, i+2); + if ind = 0 then + _setExcelCellVal(cell, Tpt.V); + cat.StrRef.StrCache.NewChildNode( array("field":"", "name":"c:pt", "obj":Tpt, "attrEx":"", "nodeType":"") ); + End; + End; + End; + + Function setDLbls(DLbls); + Begin + if Type in array('scatter','surface3d', 'wireframesurface3d', 'contour', 'wireframecontour', 'bubble', 'bubble3d') then + return; + DLbls.ShowLegendKey := ShowLegendKey; + DLbls.ShowVal := ShowVal; + DLbls.ShowCatName := ShowCatName; + DLbls.ShowSerName := ShowSerName; + DLbls.ShowBubbleSize := ShowBubbleSize; + DLbls.ShowPercent := ShowPercent; + DLbls.ShowLeaderLines := ShowLeaderLines; + End; + + Function setDpt(o, ind); + Begin + if not (Type in array('pie','pie3d')) then return; + data := Series[ind]['Values']; + if ifstring(data) then Begin + o.Dpt.IDx := 0; + o.Dpt.Bubble3D := false; + setPieSppr(o.Dpt.Sppr); + End + else if istable(data) then Begin + cnt := length(data); + r := array(); + for i:=0 to cnt-1 do Begin + dpt := TOfficeObj('TDpt'); + dpt.IDx := i; + dpt.Bubble3D := false; + if i=0 then + setPieSppr(dpt.sPpr); + r[length(r)] := array('name':'c:dPt','obj':dpt,'attrEx':'','nodeType':'','attrName':''); + End; + o.DptEx := r; + End; + End; + + Function setPieSppr(sPpr); + Begin + SpPr.SolidFill.SchemeClr.Val := 'accent1'; + SpPr.Ln.W := 25400; + SpPr.Ln.Cap := 'rnd'; + SpPr.Ln.SolidFill.SchemeClr.Val := 'lt1'; + SpPr.Sp3D.ContourW := 25400; + SpPr.Sp3D.ContourClr.SchemeClr.Val := 'lt1'; + End; + + Function setMarker(Marker, i); + Begin + if not (Type in array('scatter', 'line')) then return; + if Type = 'scatter' then + Marker.Symbol := 'circle'; + Marker.Size := 5; + if ifstring(Series[i]['Symbol']) then + Marker.Symbol := Series[i]['Symbol']; + if ifint(Series[i]['Size']) then + Marker.Size := Series[i]['Size']; + + if i < 6 then Begin + marker.SpPr.SolidFill.SchemeClr.Val := 'accent' $ (i + 1); + Marker.SpPr.Ln.W := 9252; + Marker.SpPr.Ln.SolidFill.SchemeClr.Val := 'accent' $ (i + 1); + End; + End; + + Function setSppr(SpPr, i); + Begin + if Type = 'line' then Begin + SpPr.Ln.algn := 'ctr'; + SpPr.Ln.cmpd := 'sng'; + SpPr.Ln.cap := 'rnd'; + SpPr.Ln.W := 8000; + //SpPr.Ln.NoFill := true; + SpPr.Ln.prstDash := 'solid'; + SpPr.Ln.round := true; + SpPr.Ln.SolidFill.SchemeClr.Val := 'accent' $ ((Ord+i)%6+1); + return; + End; + if Type = 'scatter' then Begin + w := Series[i]['LineWidth']; + SpPr.Ln.W := 0.25 > w || w > 999 ? 25400 : 12700 * w; + SpPr.Ln.Cap := 'rnd'; + SpPr.Ln.SolidFill.SchemeClr.Val := 'accent' $ ((Ord+i)%6+1); + return; + End; + End; + + Function getSharp(t); + Begin + m := array( + 'bar3dconeclustered': 'cone', + 'bar3dconestacked': 'cone', + 'bar3dconepercentstacked': 'cone', + 'bar3dpyramidclustered': 'pyramid', + 'bar3dpyramidstacked': 'pyramid', + 'bar3dpyramidpercentstacked': 'pyramid', + 'bar3dcylinderclustered': 'cylinder', + 'bar3dcylinderstacked': 'cylinder', + 'bar3dcylinderpercentstacked': 'cylinder', + 'col3dcone': 'cone', + 'col3dconeclustered': 'cone', + 'col3dconestacked': 'cone', + 'col3dconepercentstacked': 'cone', + 'col3dpyramid': 'pyramid', + 'col3dpyramidclustered': 'pyramid', + 'col3dpyramidstacked': 'pyramid', + 'col3dpyramidpercentstacked': 'pyramid', + 'col3dcylinder': 'cylinder', + 'col3dcylinderclustered': 'cylinder', + 'col3dcylinderstacked': 'cylinder', + 'col3dcylinderpercentstacked': 'cylinder'); + return m[t]; + End; + + Function getChartName(t); + Begin + m := array( + 'area': 'areaChart', + 'areastacked': 'areaChart', + 'areapercentstacked': 'areaChart', + 'area3d': 'area3DChart', + 'area3dstacked': 'area3DChart', + 'area3dpercentstacked': 'area3DChart', + 'bar': 'barChart', + 'barstacked': 'barChart', + 'barpercentstacked': 'barChart', + 'bar3dclustered': 'bar3DChart', + 'bar3dstacked': 'bar3DChart', + 'bar3dpercentstacked': 'bar3DChart', + 'bar3dconeclustered': 'bar3DChart', + 'bar3dconestacked': 'bar3DChart', + 'bar3dconepercentstacked': 'bar3DChart', + 'bar3dpyramidclustered': 'bar3DChart', + 'bar3dpyramidstacked': 'bar3DChart', + 'bar3dpyramidpercentstacked': 'bar3DChart', + 'bar3dcylinderclustered': 'bar3DChart', + 'bar3dcylinderstacked': 'bar3DChart', + 'bar3dcylinderpercentstacked': 'bar3DChart', + 'col': 'barChart', + 'colstacked': 'barChart', + 'colpercentstacked': 'barChart', + 'col3d': 'bar3DChart', + 'col3dclustered': 'bar3DChart', + 'col3dstacked': 'bar3DChart', + 'col3dpercentstacked': 'bar3DChart', + 'col3dcone': 'bar3DChart', + 'col3dconeclustered': 'bar3DChart', + 'col3dconestacked': 'bar3DChart', + 'col3dconepercentstacked': 'bar3DChart', + 'col3dpyramid': 'bar3DChart', + 'col3dpyramidclustered': 'bar3DChart', + 'col3dpyramidstacked': 'bar3DChart', + 'col3dpyramidpercentstacked': 'bar3DChart', + 'col3dcylinder': 'bar3DChart', + 'col3dcylinderclustered': 'bar3DChart', + 'col3dcylinderstacked': 'bar3DChart', + 'col3dcylinderpercentstacked': 'bar3DChart', + 'bubble': 'bubbleChart', + 'bubble3d': 'bubbleChart'); + return 'c:' $ m[t]; + End; + + Function getVaryColors(t); + Begin + m := array( + 'barstacked': 100, + 'barpercentstacked': 100, + 'colstacked': 100, + 'colpercentstacked': 100 + ); + return m[t]; + End; + + Function getGrouping(t); + Begin + m := array( + 'area': 'standard', + 'areastacked': 'stacked', + 'areapercentstacked': 'percentStacked', + 'area3d': 'standard', + 'area3dstacked': 'stacked', + 'area3dpercentstacked': 'percentStacked', + 'bar': 'clustered', + 'barstacked': 'stacked', + 'barpercentstacked': 'percentStacked', + 'bar3dclustered': 'clustered', + 'bar3dstacked': 'stacked', + 'bar3dpercentstacked': 'percentStacked', + 'bar3dconeclustered': 'clustered', + 'bar3dconestacked': 'stacked', + 'bar3dconepercentstacked': 'percentStacked', + 'bar3dpyramidclustered': 'clustered', + 'bar3dpyramidstacked': 'stacked', + 'bar3dpyramidpercentstacked': 'percentStacked', + 'bar3dcylinderclustered': 'clustered', + 'bar3dcylinderstacked': 'stacked', + 'bar3dcylinderpercentstacked': 'percentStacked', + 'col': 'clustered', + 'colstacked': 'stacked', + 'colpercentstacked': 'percentStacked', + 'col3d': 'standard', + 'col3dclustered': 'clustered', + 'col3dstacked': 'stacked', + 'col3dpercentstacked': 'percentStacked', + 'col3dcone': 'standard', + 'col3dconeclustered': 'clustered', + 'col3dconestacked': 'stacked', + 'col3dconepercentstacked': 'percentStacked', + 'col3dpyramid': 'standard', + 'col3dpyramidclustered': 'clustered', + 'col3dpyramidstacked': 'stacked', + 'col3dpyramidpercentstacked': 'percentStacked', + 'col3dcylinder': 'standard', + 'col3dcylinderclustered': 'clustered', + 'col3dcylinderstacked': 'stacked', + 'col3dcylinderpercentstacked': 'percentStacked', + 'line': 'standard'); + return m[t]; + End; + + Function getBarDir(t); + Begin + m := array( + 'bar': 'bar', + 'barstacked': 'bar', + 'barpercentstacked': 'bar', + 'bar3dclustered': 'bar', + 'bar3dstacked': 'bar', + 'bar3dpercentstacked': 'bar', + 'bar3dconeclustered': 'bar', + 'bar3dconestacked': 'bar', + 'bar3dconepercentstacked': 'bar', + 'bar3dpyramidclustered': 'bar', + 'bar3dpyramidstacked': 'bar', + 'bar3dpyramidpercentstacked': 'bar', + 'bar3dcylinderclustered': 'bar', + 'bar3dcylinderstacked': 'bar', + 'bar3dcylinderpercentstacked': 'bar', + 'col': 'col', + 'colstacked': 'col', + 'colpercentstacked': 'col', + 'col3d': 'col', + 'col3dclustered': 'col', + 'col3dstacked': 'col', + 'col3dpercentstacked': 'col', + 'col3dcone': 'col', + 'col3dconestacked': 'col', + 'col3dconeclustered': 'col', + 'col3dconepercentstacked': 'col', + 'col3dpyramid': 'col', + 'col3dpyramidclustered': 'col', + 'col3dpyramidstacked': 'col', + 'col3dpyramidpercentstacked': 'col', + 'col3dcylinder': 'col', + 'col3dcylinderclustered': 'col', + 'col3dcylinderstacked': 'col', + 'col3dcylinderpercentstacked': 'col', + 'line': 'standard'); + return m[t]; + End; + + isWord_; +End; + +Type TPageLine = Class + Function Create(w); + Begin + Width := w; + Init(); + End; + + Function Init(); + Begin + MaxLineHeight := 0; + CurrentLine := 0; + txt_ := ''; + End; + + Function Add(ch, rowHeight, rPr); + Begin + newLine := false; + txt := txt_; + [charW, cnt] := _getCharWidth(ch, rPr); + if CurrentLine + charW > Width then Begin + mh := MaxLineHeight; + Init(); //新行 + newLine := true; + End; + CurrentLine += charW; + if rowHeight > MaxLineHeight then + MaxLineHeight := rowHeight; + return array(newLine, mh, cnt, txt); + End; + + Function _getCharWidth(ch, rPr); + Begin + iChar := ord(ch); + cnt := iChar > 127 ? 2 : 1; + ratio := cnt=1 ? 0.5 : 1; + if ifObj(rPr) then Begin + size := max(rPr.Size, rPr.szCs); + if size=0 then size := 21; + return array(size * 10 * ratio, cnt); + End; + return array(210 * ratio, cnt); //默认五号字 + End; + + Width:integer; + MaxLineHeight:integer; + CurrentLine:integer; + txt_:string; +End; + +//页面设置 +Type TSectPr = Class + Function Create(docx, node); + Begin + docx_ := docx; + PageNo := 1; + LinePos := 0; + PageHash := array(); + ContentArr := array(); + if ifObj(node) then + Init(node); + End; + + Function Init(node); + Begin + pgSz := node.FirstChildElement('w:pgSz'); + if ifObj(pgSz) then Begin + w := pgSz.GetAttribute('w:w'); + h := pgSz.GetAttribute('w:h'); + End; + pgMar := node.FirstChildElement('w:pgMar'); + if ifObj(pgMar) then Begin + left := pgMar.GetAttribute('w:left'); + right := pgMar.GetAttribute('w:right'); + top := pgMar.GetAttribute('w:top'); + bottom := pgMar.GetAttribute('w:bottom'); + End; + PageWidth := Class(TSXml).SafeStrToIntDef(w, 11906)-Class(TSXml).SafeStrToIntDef(left,1800)-Class(TSXml).SafeStrToIntDef(right,1800); + PageHeight := Class(TSXml).SafeStrToIntDef(h, 16838)-Class(TSXml).SafeStrToIntDef(top,1440)-Class(TSXml).SafeStrToIntDef(bottom,1440); + docGrid := node.FirstChildElement('w:docGrid'); + LinePitch := ifObj(docGrid) ? Class(TSXml).SafeStrToIntDef(docGrid.GetAttribute('w:linePitch'), 312) : 312; + PageLine := new TPageLine(PageWidth); + if istable(ContentArr) then Begin //计算当前章节页码 + //w:p;w:tbl + for i:=0 to length(ContentArr)-1 do Begin + [startPage,PageNo,LinePos] := _CalcPage(ContentArr[i]['obj'], PageNo, LinePos);//计算段落、表格、文本框、图片、形状等的页面及大小 + if ContentArr[i]['mark'] >= 0 then + PageHash[ ContentArr[i]['mark'] ] := startPage;//记录页面 + End; + + //下一章节 + PageNo ++; + ContentArr := array(); + LinePos := 0; + End; + End; + + Function Append(p); + Begin + ContentArr[ length(ContentArr) ] := array('obj':p, 'mark':-1); + End; + + Function Mark(ind); + Begin + if istable(ContentArr) then + ContentArr[ length(ContentArr)-1 ]['mark'] := ind; + End; + + Function GetPageNo(ind); + Begin + if ifInt(PageHash[ind]) then + return PageHash[ind]; + return PageNo; + End; + + //计算页面 + Function _CalcPage(obj, page, lpos, more); + Begin + startPage := page; + curPageNo := page; + curLinePos := lpos; + case obj.Name() of + 'w:p': + [startPage, pgNo, line] := _CalcParagraphPage(obj, curPageNo, curLinePos, more); + 'w:tbl': + [startPage, pgNo, line] := _CalcTablePage(obj, curPageNo, curLinePos); + End; + return array(startPage, pgNo, line); + End; + + //段落 + Function _CalcParagraphPage(p, page, lpos, more); + Begin + startPage := page; + curPageNo := page; + curLinePos := lpos; + height := 0;//单位:点(1点=0.3527毫米=1/72英寸) + ETU := 360045;//1cm单位 + defaultLineHeight := LinePitch; //缺省行距 + ParagraphLineHeight := LinePitch; + + defaultPpr := docx_.StyleObject().defaultPpr_;//缺省段落 + defaultRpr := docx_.StyleObject().defaultRpr_;//缺省字体 + pPr := Class(TSXml).ReadPprFormat(p.node_); + //存在段落样式 + StyleId := p.pPr.Value('StyleId'); + if StyleId then Begin + oStyle := docx_.StyleObject().GetStyleById(StyleId); + if ifObj(oStyle) then Begin + stylePpr := oStyle.ReadPprFormat(); //读段落属性(缓存到StyleObject中) + if not ifObj(pPr) then Begin + pPr := stylePpr; + End + else + Class(TSXml).CopyPprFormat(pPr, stylePpr); + //Class(TSXml).CopyPprFormat(pPr, defaultPpr); + + defaultRpr := oStyle.ReadRprFormat(); //读段落字体属性(缓存到StyleObject中) + End; + End + else if ifObj(defaultPpr) then Begin //缺省样式 + if not ifObj(pPr) then Begin + pPr := defaultPpr; + End + else + Class(TSXml).CopyPprFormat(pPr, defaultPpr); + End; + + LineRatio := 1.0; + if ifObj(pPr) then Begin + if pPr.LineSpacingRule = 'exact' and pPr.LineSpacing then //固定行距 + defaultLineHeight := pPr.LineSpacing; + else if pPr.LineSpacing then Begin + LineRatio := pPr.LineSpacing / 240; + //LineRatio := 1.0; + defaultLineHeight := LineRatio * defaultLineHeight; //多倍行距 + End; + ParagraphLineHeight := _GetHeightRatio(pPr, pPr.rPr, LineRatio) * defaultLineHeight; //缺省段落高度(字体) + End; + + //段前 + before := (ifObj(pPr)) ? pPr.SpaceBefore : 0; + after := ifObj(pPr) ? pPr.SpaceAfter : 0; + //段中 + runs := p.GetRuns(); + for i:=0 to length(runs)-1 do Begin + run := runs[i]; + rPr := Class(TSXml).ReadRprFormat(run.node_); + if not ifObj(rPr) then + rPr := defaultRpr; + else + Class(TSXml).CopyRprFormat(rPr, defaultRpr); +//_dumpRpr(rpr); + RunLineHeight := _GetHeightRatio(pPr, rPr, LineRatio) * defaultLineHeight; //缺省段落高度 + pic := run.node_.FirstChildElement('w:drawing/wp:inline/wp:extent');//图片 + if not ifObj(pic) then + pic := run.node_.FirstChildElement('mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:extent');//文本框 + if ifObj(pic) then Begin + cy := Class(TSXml).SafeStrToIntDef(pic.GetAttribute('cy'), LinePitch); + height := cy / ETU / 0.0325; + _addLine(startPage, curPageNo, curLinePos, height, before, linesCnt ? false : true, txt); //加入一行 + linesCnt ++; + continue; + End + + node := run.node_.FirstChildElement(); + while ifObj(node) do Begin + name := node.GetName(); + if name = 'w:br' then Begin + _addLine(startPage, curPageNo, curLinePos, (PageLine.MaxLineHeight ? PageLine.MaxLineHeight : RunLineHeight) + (linesCnt ? 0 : more), 0, linesCnt ? false : true, ''); //加入一行 + PageLine.Init(); + linesCnt ++; + End + else if name = 'w:t' then Begin + txt := node.GetText(); + txtLen := length(txt); + n := 0; + while n < txtLen do Begin + if ifObj(pPr) and PageLine.CurrentLine = 0 then Begin //缩进、悬挂 + PageLine.CurrentLine += _getHanging(linesCnt, pPr); + End; + [newLine, LineHeight, cnt, t] := PageLine.Add(txt[n+1], RunLineHeight, rPr); + PageLine.txt_ += txt[n+1:n+cnt]; + n += cnt; + if newLine then Begin + _addLine(startPage, curPageNo, curLinePos, LineHeight + (linesCnt ? 0 : more), before, linesCnt ? false : true, t); //加入一行 + if ifObj(pPr) then + PageLine.CurrentLine += _getHanging(linesCnt+1, pPr); + linesCnt ++; + End; + End; + End; + node := node.NextElement(); + End; + End; + if linesCnt = 0 and PageLine.CurrentLine = 0 then Begin //空行 + _addLine(startPage, curPageNo, curLinePos, ParagraphLineHeight + more, 0, true, ''); //加入一行 + End + else if PageLine.CurrentLine then Begin + _addLine(startPage, curPageNo, curLinePos, PageLine.MaxLineHeight, before, linesCnt ? false : true, PageLine.txt_); //加入一行 + PageLine.Init(); + linesCnt ++; + End + else Begin + PageLine.Init(); + End; + //段后 +//_dumpPpr(pPr); +//println('Begin Orer=curLinePos={}',curLinePos); + curLinePos += after; +//println('End Orer=curLinePos={}\n\n\n\n',curLinePos); + return array(startPage, curPageNo, curLinePos); + End; + + //表格 + Function _CalcTablePage(tbl, page, lpos); + Begin + startPage := page; + curPageNo := page; + curLinePos := lpos; + topH := Class(TSXml).SafeStrToIntDef(tbl.tblPr.Borders.Top.Value('Val'), 4); //缺省0.5磅,一磅=20点 + bottomH := Class(TSXml).SafeStrToIntDef(tbl.tblPr.Borders.bottom.Value('Val'), 4); //缺省0.5磅 + insideVH := Class(TSXml).SafeStrToIntDef(tbl.tblPr.Borders.insideV.Value('Val'), 4); //缺省0.5磅 + iRow := 0; + trNode := tbl.node_.FirstChildElement('w:tr'); + while ifObj(trNode) do Begin + maxPageNo := curPageNo; + maxLinePos := curLinePos; + tr := new TwTr(nil, 'w:tr'); + tr.RootObj := trNode; + vh := Class(TSXml).SafeStrToIntDef(tr.tblPrEx.Borders.insideV.Value('Val'), insideVH); //行的上边框 + tcNode := trNode.FirstChildElement('w:tc'); + while ifObj(tcNode) do Begin //计算每一个单元格占用页面 + tcPageNo := curPageNo; + tcLinePos := curLinePos; + iCol := 0; + pNode := tcNode.FirstChildElement(); + while ifObj(pNode) do Begin + name := pNode.GetName(); + obj := _getDocObject(pNode, name); + if ifObj(obj) then Begin + [tcStartPage,tcPageNo,tcLinePos] := _CalcPage(ContentArr[i]['obj'], tcPageNo, tcLinePos, iCol = 0 ? (iRow = 0 ? topH * 2.5 : vh * 2.5) : 0); + iCol ++; + End; + pNode := pNode.NextElement(); + End; + if iCol = 0 then Begin //空单元格 + _addLine(tcStartPage, tcPageNo, tcLinePos, (iRow = 0 ? topH * 2.5 : vh * 2.5) + LinePitch, 0, false, ''); + End; + if maxPageNo < tcPageNo then Begin + maxPageNo := tcPageNo; + maxLinePos := tcLinePos; + End + else if maxPageNo = tcPageNo and maxLinePos < tcLinePos then Begin + maxLinePos := tcLinePos; + End; + tcNode := tcNode.NextElement('w:tc'); + End; + iRow++; + trNode := trNode.NextElement('w:tr'); + curPageNo := maxPageNo; + curLinePos := maxLinePos; + End; + //底边框 + _addLine(startPage, curPageNo, curLinePos, bottomH * 2.5, 0, false, ''); + + return array(startPage, curPageNo, curLinePos); + End; + + Function _addLine(startPage, curPageNo, curLinePos, height, before, firstLine, t); + Begin +//println('换行:curLinePos={},height={}, before={}, txt={}',curLinePos, height, before, t); + if curLinePos + height > PageHeight then Begin //放不下,换页 + curPageNo++; + curLinePos := height; +//println('换页:curLinePos={},txt={}',curLinePos, t); + End + else + curLinePos += height + (curLinePos = 0 ? 0 : before); + if firstLine then + startPage := curPageNo; + End; + + Function _GetHeightRatio(pPr, rPr, LineRatio); + Begin + if lineRule = 'exact' then //固定行距 + return 1.0; + if not ifObj(rPr) then + return 1.0; + + return _Font2LineHeight(rPr, LineRatio); //字体大小对应的行距(倍数) + End; + + Function _Font2LineHeight(rPr, LineRatio); + Begin + size := max(ifnil(rPr.Size) ? 0 : rPr.Size, ifnil(rPr.szCs) ? 0 : rPr.szCs); + if size = 0 then size := 21;//缺省五号字 + if rPr.rFont.hint in array('eastAsia', 'zh-CN') or rPr.rFont.eastAsia <> '' then Begin + return ceil(size*10/(LinePitch*LineRatio-200/3)); + End; + + return ceil(size*10/(LinePitch*LineRatio-38)); + End; + + docx_; + PageWidth:integer; + PageHeight:integer; + LinePitch:integer; //行距 + PageNo; + LinePos; + ContentArr; + PageHash; + PageLine; +End; + +//w:body +Type TDocumentBody = Class(DocObject) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + name_ := 'w:body'; + InitNode(node); + End; + + Function InitNode(node); + Begin + node_ := node; + //设置最后一个段落 + _setLastParagraph(); + End; + + Function _setLastParagraph(); + Begin + lastParagraph_ := nil; + if ifObj(node_) then Begin + last := node_.LastChild(); + while ifObj(last) do Begin + name := last.GetName(); + if name in array('w:p', 'w:tbl') then Begin + lastParagraph_ := last; + break; + End; + last := last.Prev(); + End; + End; + End; + + ///返回文档中全部对象列表(TParagraph、TTable等) + Function Parts(); + Begin + return getDocumentObjects(node_, ''); + End; + + ///word文档所有段落 + ///返回:TParagraph对象数组 + Function Paragraphs(); + Begin + parts := getDocumentObjects(node_, 'w:p'); + r := array(); + for i:=0 to length(parts)-1 do Begin + r[i] := new TParagraph(parts[i].node_); + End; + return r; + End; + + ///word最后一个段落 + ///返回:TParagraph对象 + Function LastParagraph(); + Begin + node := node_.LastChildElement('w:p'); + return ifObj(node) ? new TParagraph(node) : nil; + End; + + ///添加新段落 + ///paragraph: TParagraph对象 + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 + ///[styleId]: int 样式ID + ///返回TParagraph对象 + Function AddParagraph(paragraph, posOpt, styleId); + Begin + if ifString(styleId) and styleId <> '' then Begin + paragraph.Format.StyleId := styleId; + End; + addPart(posOpt, paragraph); + p := new TParagraph(paragraph.node_); + //复制段落字体属性 + p.CopyRunFormat(false, nil); + _set_lastParagraph_(posOpt, p.node_);//设置最后一个段落 + return p; + End; + + ///复制w:p节点内容 + ///paragraphObj: TParagraph对象 + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 + ///返回TParagraph对象 + Function CopyWp(paragraphObj, posOpt); + Begin + addPart(posOpt, paragraphObj, true); + p := new TParagraph(paragraphObj.node_); + //复制段落字体属性 + p.CopyRunFormat(false, nil); + _set_lastParagraph_(posOpt, p.node_);//设置最后一个段落 + return p; + End; + + ///复制w:tbl节点内容 + ///ttable: TTable对象 + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 + ///返回TTable对象 + Function CopyWtbl(table, posOpt); + Begin + addPart(posOpt, table, true); + p := new TTable(table.node_); + _set_lastParagraph_(posOpt, p.node_); + return p; + End; + + ///删除指定段落 + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 第N段;posOpt段落 + ///返回:true + Function DelParagraph(posOpt); + Begin + node := findNode(posOpt, false); + if ifInt(node) then Begin + if node = 0 then + node := node_.FirstChildElement('w:p'); + else if node = -1 then + node := lastParagraph_; + End; + if not ifObj(node) then + return false; + reset_position := false; + if ifObj(TOfficeApi().GetCurrentPosition()) and node.Eq(TOfficeApi().GetCurrentPosition()) then + reset_position := true; + next := node.NextElement('w:p'); + node_.DeleteChild(node); + if not ifObj(next) then + _setLastParagraph(); + if reset_position then + TOfficeApi().Set('CurrentPosition', lastParagraph_); + return true; + End; + + ///添加标题 + ///title: string + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 + ///level: int 标题级别(0-9) + ///返回TParagraph对象 + Function AddHeading(title, posOpt, styleId); + Begin + paragraph := new TParagraph(); + paragraph.Run.SetText( title ); + if ifObj(document_) then Begin + id := document_.GetBookMarkID(); + paragraph.MarkStart.Name := '_Toc' $ id; + paragraph.MarkStart.ID := id; + paragraph.MarkEnd.ID := id; + End; + return AddParagraph(paragraph, posOpt, styleId); + End; + + ///插入分页符 + ///posOpt: 段落位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加段落 + ///返回TParagraph对象 + Function AddBreak(posOpt, tp); + Begin + paragraph := new TParagraph(); + if tp <> '' then + paragraph.Run.Br.Type := tp; + return AddParagraph(paragraph, posOpt); + End; + + //word文档所有内容的文本串数组,包含段落信息 + //返回:array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r)) + Function TextArray();override; + Begin + r := array(); + ps := getDocumentObjects(node_, 'w:p'); + for i:=0 to length(ps)-1 do Begin + pArr := ps[i].TextArray(); + if length(pArr) then Begin + update pArr set ['pIndex'] = i end; + r union= pArr; + End + else Begin + r[ length(r) ] := array('pNode':ps[i].node_, 'pIndex':i, 'rNode':nil, 'rIndex':-1);//空段落 + End; + End; + return r; + End; + + ///word文档所有表格个数 + ///返回:int + Function TablesCount(); + Begin + t := getDocumentObjects(node_, 'w:tbl'); + return length(t); + End; + + ///word文档所有表格 + ///返回:TTable对象数组 + Function Tables(); + Begin + return getDocumentObjects(node_, 'w:tbl'); + End; + + ///word文档指定表格 + ///n: int 第n个表格 + ///返回:TTable对象 + Function GetTable(i); + Begin + t := getDocumentObjects(node_, 'w:tbl'); + if i < 0 or i >= length(t) then return 0; + tbl := new TTable(t[i].node_); + return tbl; + End; + + ///插入数据表 + ///tbl: TTable对象 + ///[posOpt: 段落位置],0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加表格 + Function InsertTable(tbl, posOpt, customCell); + Begin + addPart(posOpt, tbl); + TOfficeApi().Set('CurrentTable', tbl.node_); + tblBorders := class(TSXml).GetNode(tbl.node_, 'w:tblPr/w:tblBorders'); + tblCellMar := class(TSXml).GetNode(tbl.node_, 'w:tblPr/w:tblCellMar'); + if ifObj(tblBorders) or ifObj(tblCellMar) then Begin + borders := ifObj(tblBorders) ? tblBorders.Marshal() : nil; + cellmar := ifObj(tblCellMar) ? tblCellMar.Marshal() : nil; + End; + defaultParagraph := tbl.Paragraph; + if not ifObj(defaultParagraph) then Begin + defaultParagraph := new TParagraph(); + defaultParagraph.pPr.rPr.Lang := 'en-US'; + defaultParagraph.pPr.rPr.eastAsia := 'zh-CN'; + defaultParagraph.Run.rPr.Lang := 'en-US'; + defaultParagraph.Run.rPr.eastAsia := 'zh-CN'; + End; + defaultpPr := defaultParagraph.pPr.Marshal(); + defaultrPr := defaultParagraph.pPr.rPr.Marshal(); + + for i:=0 to length(tbl.Data_)-1 do Begin + trNode := tbl.node_.InsertEndChild('element', 'w:tr'); + trNode.InsertEndChild('element', 'w:trPr'); + multiLine := false; + for j:=0 to tbl.colCount_-1 do Begin + if ifstring(tbl.Data_[i, j]) and Pos('\n', tbl.Data_[i, j]) then + multiLine := true; + //对象太多的话,对象效率奇慢,优化掉(性能可能相差50倍) + if 0 then Begin + tc := new TCell(); + tc.TcPr.Width := tbl.TblGrid.GridCol[j]['obj'].W; + tc.TcPr.Type := 'dxa'; + tc.SetText(tbl.Data_[i, j]); + trNode.InsertEndChild(tc.Marshal()); + continue; + End; + + tcNode := trNode.InsertEndChild('element', 'w:tc'); + if istable(customCell) and ifObj(customCell[i, j, 0]) then + begin + tcNode.InsertEndChild(customCell[i, j, 0].Marshal()); + end + else begin + tcPrNode := tcNode.InsertEndChild('element', 'w:tcPr'); + tcWNode := tcPrNode.InsertEndChild('element', 'w:tcW'); + tcWNode.SetAttribute('w:w', tbl.TblGrid.GridCol[j]['obj'].W); + tcWNode.SetAttribute('w:type', 'dxa'); + end + + if multiLine then Begin + defaultParagraph.node_ := nil; + defaultParagraph.Run.ClearText(); + defaultParagraph.Run.SetText(tbl.Data_[i, j]); + tcNode.InsertEndChild(defaultParagraph.Marshal()); + End + else Begin + pNode := tcNode.InsertEndChild('element', 'w:p'); + if istable(customCell) and ifObj(customCell[i, j, 1]) then + pNode.InsertEndChild(customCell[i, j, 1].Marshal()); + else + pNode.InsertEndChild(defaultpPr); + rNode := pNode.InsertEndChild('element', 'w:r'); + if istable(customCell) and ifObj(customCell[i, j, 2]) then + rNode.InsertEndChild(customCell[i, j, 2].Marshal()); + else + rNode.InsertEndChild(defaultrPr); + tNode := rNode.InsertEndChild('element','w:t', class(TSXml).CurCodePageToUtf8(tbl.Data_[i, j])); + if _preserve(tbl.Data_[i, j]) then + tNode.SetAttribute('xml:space', 'preserve'); + End; +(* + + + + + + + + + + + + + + + Index + + + +*) + End; + //if ifObj(tblCellMar) then Begin + // c := class(TSXml).GetNode(trNode, 'w:tblPrEx/w:tblCellMar', 'first'); + // class(TSXml).UpdateNode(c, cellmar[0]['attributes'], cellmar[0]['children']); + //End; + //if ifObj(tblBorders) then Begin + // b := class(TSXml).GetNode(trNode, 'w:tblPrEx/w:tblBorders', 'first'); + // class(TSXml).UpdateNode(b, borders[0]['attributes'], borders[0]['children']); + //End; + End; + node_.Parent().SetAttribute('mc:Ignorable', 'w14 w15 wp14'); + node_.Parent().SetAttribute('xmlns:w15', 'http://schemas.microsoft.com/office/word/2012/wordml'); + _set_lastParagraph_(posOpt, tbl.node_); + + p := new TTable(tbl.node_); + return p; + End; + + ///插入图片 + ///picture: TPicture对象 + ///[posOpt: 段落位置],0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加表格 + ///[docx]: 可选参数,TSDocxFile对象,在TTextBox、TCell中调用需要传入文档对象 + Function AddPicture(picture, posOpt, docx); + Begin + if ifObj(docx) then Begin + zipfile_ := docx.Zip(); + picture.Run.Drawing.WInline.ID := docx.GetDocPrId(); + End; + if not ifBinary(picture.Image) or length(picture.Image)=0 then + raise 'Invalid Image Data.'; + if not ifObj(zipfile_) then + raise 'no support'; + image := new TSImage(picture.Image); + xml := zipfile_.Get('word/_rels/document.xml.rels'); + files := sselect ['FileName'] from zipfile_.Files() where AnsiStartsText('word/media/image', ['FileName']) end; + for i:=0 to length(files)-1 do Begin + if zipfile_.Diff(files[i], picture.Image) = 0 then Begin + prefix := ReplaceStr(files[i], 'word/', ''); + [maxRid, imageFile, rid] := class(TSXml).FindRelationshipRid(xml, prefix); + End; + End; + if rid = 0 then Begin + imageCnt := length(files) + 1; + imageFile := 'media/image' $ imageCnt $ '.' $ image.ExtFileName; + [rid, target] := class(TSXml).FindRelationshipRid(xml, ''); + rid ++; + class(TSXml).AddRelationshipRid(xml, imageFile, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'rId' $ rid); + zipfile_.Add('word/' + imageFile, picture.Image); + contentXml := zipfile_.Get('[Content_Types].xml'); + class(TSXml).AddDefaultContentType(contentXml, image.ExtFileName, 'image/' $ image.ExtFileName); + End; + [cx, cy] := picture.ScaledDimensions(image);//extent 元素通过其属性指定此对象的高度和宽度为 [cx,cy] ETU (英语公制单位) + //println('cx={},cy={},w={},h={}',cx,cy,image.px_width,image.px_height); + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.BlipFill.blip.Embed := 'rId' $ rid; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.BlipFill.Stretch.FillRect := 1; + picId := getPictureMaxId() + 1; + picture.Run.Drawing.WInline.Name := '图片 ' $ picId; + picture.Run.Drawing.WInline.Descr := class(TSXml).CurCodePageToUtf8(picture.Descr); + picture.Run.Drawing.WInline.cNvGraphicFramePr.xmlns := 'http://schemas.openxmlformats.org/drawingml/2006/main'; + picture.Run.Drawing.WInline.cNvGraphicFramePr.noChangeAspect := 1; + picture.Run.Drawing.WInline.Graphic.xmlns := 'http://schemas.openxmlformats.org/drawingml/2006/main'; + picture.Run.Drawing.WInline.Graphic.GraphicData.uri := 'http://schemas.openxmlformats.org/drawingml/2006/picture'; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.xmlns := 'http://schemas.openxmlformats.org/drawingml/2006/picture'; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.CNvPr.ID := picture.Run.Drawing.WInline.ID; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.CNvPr.Name := picture.Run.Drawing.WInline.Name; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.CNvPr.Descr := picture.Run.Drawing.WInline.Descr; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.cNvPicPr.NodeName := 'pic:cNvPicPr'; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.nvPicPr.cNvPicPr.PicLocks := 1; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.PrstGeom.prst := 'rect'; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.PrstGeom.avLst := true; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Off.X := 0; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Off.Y := 0; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Ext.CX := cx; + picture.Run.Drawing.WInline.Graphic.GraphicData.Pic.spPr.XFrm.Ext.CY := cy; + picture.Run.Drawing.WInline.distR := 114300; + picture.Run.Drawing.WInline.distL := 114300; + picture.Run.Drawing.WInline.distB := 0; + picture.Run.Drawing.WInline.distT := 0; + picture.Run.Drawing.WInline.cy := cy; + picture.Run.Drawing.WInline.cx := cx; + //picture.Run.Drawing.WInline.r := 0; + //picture.Run.Drawing.WInline.b := 5080; + //picture.Run.Drawing.WInline.t := 0; + //picture.Run.Drawing.WInline.l := 0; + addPart(posOpt, picture); + + p := new TPicture(picture.node_); + _set_lastParagraph_(posOpt, picture.node_); + picture.node_.InsertFirstChild('element', 'w:pPr'); + TOfficeApi().Set('CurrentShape', picture.node_); + return p; + End; + + ///文档中全部的批注信息 + ///返回:TDocComments对象 + Function Comments();overload; + Begin + t := array(); + [startCnt, endCnt, tCnt, index] := array(0, 0, 0, 0); + p := node_.FirstChildElement('w:p'); + while ifObj(p) do Begin + child := p.FirstChildElement(); + rIndex := 0; + while ifObj(child) do Begin + id := -1; + name := child.GetName(); + if name = 'w:commentRangeStart' then Begin + startCnt ++; + id := strtoint(child.GetAttribute('w:id')); + t[ tCnt++ ] := array('pNode':p, 'rNode':child, 'Name':name, 'Start':startCnt, 'End':endCnt, 'ID':id, 'pIndex':index); + End + else if name = 'w:commentRangeEnd' then Begin + endCnt ++; + id := strtoint(child.GetAttribute('w:id')); + t[ tCnt++ ] := array('pNode':p, 'rNode':child, 'Name':name, 'Start':startCnt, 'End':endCnt, 'ID':id, 'pIndex':index); + End + else if name = 'w:r' and startCnt > endCnt then Begin + t[ tCnt++ ] := array('pNode':p, 'rNode':child, 'Name':name, 'Start':startCnt, 'End':endCnt, 'ID':-1, 'pIndex':index); + End; + child := child.NextElement(); + End; + index ++; + p := p.NextElement('w:p'); + End; + return new TDocComments(t); + End; + + //返回TDocSection对象集合 + Function Sections();overload; + Begin + index := 0; + r := array(); + node := node_.FirstChildElement(); + while ifObj(node) do Begin + name := node.GetName(); + if name = 'w:sectPr' then Begin + section := new TDocSection(node, index++, zipfile_); + r[length(r)] := section; + End + else if name = 'w:p' then Begin + child := class(TSXml).GetNode(node, 'w:pPr/w:sectPr', false); + if ifObj(child) then Begin + section := new TDocSection(node, index++, zipfile_); + r[length(r)] := section; + End; + End; + node := node.NextElement(); + End; + return r; + End; + + //index:integer 章节索引 + //返回:指定TDocSection对象 + Function Sections(index);overload; + Begin + if index < 0 then Begin //返回文档最后一个章节(缺省章节) + node := node_.LastChild('w:sectPr'); + if ifObj(node) then + return new TDocSection(node, -1, zipfile_); + return nil; + End; + arr := Sections(); + if length(arr) >= index then + return nil; + return arr[index]; + End; + + //添加章节 + //section:TDocSection对象 + //posOpt: 位置,0 在DOCX文件开头;-1 文件尾;N 在第N段之后;DocumentPart对象 在posOpt之后新添加章节 + //返回:TDocSection对象 + Function AddSection(section, posOpt);overload; + Begin + section.zipfile_ := zipfile_; + p := new TParagraph(); + p.pPr.NewChildNode( array("field":"", "name":"w:sectPr", "obj":section, "attrEx":"", "nodeType":"") ); + p := AddParagraph(p, posOpt, '');//段落对象 + sec := new TDocSection(p.node_, -2, zipfile_); + sec.NodeUri := 'w:pPr/w:sectPr'; + return sec; + End; + + Function ExecInnerTSL(docx); + Begin + //表格 + t := array(); + tslFuncCount := 0; + errArr := array(); + tArr := Tables(); + for i:=0 to length(tArr)-1 do Begin + col := tArr[i].Cols(); + row := tArr[i].Rows(); + for r:= 1 to row do Begin + for c:=1 to col do Begin + cell := tArr[i].Cell(r, c); + [err, cnt, err] := cell.ExecInnerTSL(docx);//递归 + tslFuncCount += cnt; + errArr union= err; + End; + End; + End; + + //文本框 + ps := Paragraphs(); + for i:=0 to length(ps)-1 do Begin + boxs := ps[i].TextBoxs(); + for j:=0 to length(boxs)-1 do Begin + [err, cnt, err] := boxs[j].ExecInnerTSL(docx);//递归 + if cnt then + boxs[j].Apply(); + tslFuncCount += cnt; + errArr union= err; + End; + End; + + //页脚、页眉 + sArr := Sections(); + tpArr := array('default','even','first'); + for i:=0 to length(sArr)-1 do Begin + for k, name in tpArr do Begin + h := sArr[i].Header(name); + if ifObj(h) then Begin + [err, cnt, err] := h.ExecInnerTSL(docx);//递归 + tslFuncCount += cnt; + errArr union= err; + End; + + f := sArr[i].Footer(name); + if ifObj(f) then Begin + [err, cnt, err] := f.ExecInnerTSL(docx);//递归 + tslFuncCount += cnt; + errArr union= err; + End; + End; + End; + + [err, cnt, err] := ExecInnerTSLImpl(docx); + tslFuncCount += cnt; + errArr union= err; + return array(length(errArr), tslFuncCount, errArr); + End; + + Function RunTslCode(code, err); + Begin + try + //println('run code=[{}]', code); + if code <> '' then + eval(&code); + except + err := ExceptObject.ErrInfo; + return false; + End; + return true; + End; + + Function ExecInnerTSLImpl(docx); + Begin + tslFuncCount := 0; + errArr := array(); + tslArr := array(); + tArr := TextArray(); + flag := ''; + code := nil; + begParagraphIndex := -1; + begPos := 0; + begTxtLen := 0; + while i < length(tArr) do Begin + txt := ''; + iStep := 1; + if ifObj(tArr[i]['rNode']) then Begin + run := new TRun(tArr[i]['rNode']); + txt := run.Text(); + if class(TSXml).IsUtf8() then + txt := UTF8ToAnsi(txt); + End; + k := 1; + wz := 1; + txtLen := length(txt); + while k <= txtLen do Begin + c := txt[k]; + case flag of + '': + if c = '[' then Begin + flag := '['; + begParagraphIndex := i; + begPos := wz; + begTxtLen := txtLen; + End; + '[': + if c = 'T' or c = 't' then + flag := '[T'; + else + flag := ''; + '[T': + if c = 'S' or c = 's' then + flag := '[TS'; + else + flag := ''; + '[TS': + if c = 'L' or c = 'l' then + flag := '[TSL'; + else + flag := ''; + '[TSL': + if c = ']' then Begin + flag := '[TSL]'; + tslArr := tArr[begParagraphIndex:i,:]; + code := ''; + k++; + wz++; + continue; + End + else + flag := ''; + '[TSL]': + if c = '[' then Begin + flag := '[TSL]['; + endPos := 0; + End + '[TSL][': + if c = '/' then + flag := '[TSL][/'; + else + flag := '[TSL]'; + '[TSL][/': + if c = 'T' or c='t' then + flag := '[TSL][/T'; + else + flag := '[TSL]'; + '[TSL][/T': + if c = 'S' or c='s' then + flag := '[TSL][/TS'; + else + flag := '[TSL]'; + '[TSL][/TS': + if c = 'L' or c='l' then + flag := '[TSL][/TSL'; + else + flag := '[TSL]'; + '[TSL][/TSL': + if c = ']' then Begin + tslBegParagraphNode := tslArr[0]['pNode']; + tslEndParagraphNode := tArr[i]['pNode']; + ind := length(tslArr) - 1; + if tslArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tslArr[ind]['rIndex'] <> tArr[i]['rIndex'] then Begin + ind ++; + tslArr[ind] := tArr[i]; + End; + if begPos > 1 then Begin //函数前分割为新的w:r + prevRun := run._duplicate_r(tArr[begParagraphIndex]['rNode']); + run._adjust_r(tArr[begParagraphIndex]['rNode'], 0, begPos - 1); + tslArr[0]['rNode'] := prevRun; + End; + if k < txtLen then Begin //函数后面分割为新的w:r + oldNode := run.node_; + if begParagraphIndex = i and begPos > 1 then + oldNode := prevRun; + tArr[i]['rNode'] := run._duplicate_r(oldNode); + run._adjust_r(tArr[i]['rNode'], wz, txtLen); + iStep := 0; + End; + curRunNode := tslArr[0]['rNode']; + curRun := new TRun(curRunNode); + curRun.ClearText(); + rmvPara := array(); + for m := 1 to length(tslArr) - 1 do Begin + if ifObj(tslArr[m]['rNode']) then Begin + tslArr[m]['pNode'].DeleteChild(tslArr[m]['rNode']); + hasrNode := tslArr[m]['pNode'].FirstChildElement('w:r'); + if not ifObj(hasrNode) then + rmvPara[ tslArr[m]['pIndex'] ] := tslArr[m]['pNode']; + End + else + rmvPara[ tslArr[m]['pIndex'] ] := tslArr[m]['pNode']; + End; + for index, pNode in rmvPara do Begin + pNode.Parent().DeleteChild(pNode); + End; + //run inner tsl + code := leftstr(code, lengthW(code) - 5 - endPos); + CodePage := TOfficeApi().Get('CodePage'); + TOfficeApi().Set('Docx', docx); + TOfficeApi().Set('CurrentParagraph', tslBegParagraphNode); + TOfficeApi().Set('CurrentPosition', tslBegParagraphNode); + TOfficeApi().Set('CurrentRun', curRunNode); + TOfficeApi().Set('CodePage', 'gbk'); + if not RunTslCode(code, err) then Begin + echo 'run code=',code,',err=', err, '\n'; + errArr[ length(errArr) ] := array('code':code, 'err':err); + End; + tslFuncCount ++; + tNode := curRun.node_.FirstChildElement('w:t'); + if not ifObj(tNode) then Begin //没有在外部插入文字 + tslBegParagraphNode.DeleteChild(curRunNode); + //兼容WordTemplate函数,不删除空段落(TSL脚本段落) + //hasrNode := tslBegParagraphNode.FirstChildElement('w:r'); + //if not ifObj(hasrNode) then Begin//删除空段落 + // tslBegParagraphNode.Parent().DeleteChild(tslBegParagraphNode); + // tslBegParagraphNode := nil; + //End; + End; + //段落炸裂 + curPosotion := TOfficeApi().Get('CurrentPosition'); + if i+iStep < length(tArr) and tArr[i+iStep]['pNode'] = tslEndParagraphNode and tslBegParagraphNode <> curPosotion then Begin + data := tslEndParagraphNode.Marshal(); + NewParagraphNode := tslEndParagraphNode.Parent().InsertAfterChild(curPosotion, data[0]);//复制段落 + rmvArr := array(); + cnt := 0; + curLine := 0; + prevRNode := tArr[i+iStep]['rNode'].PrevElement('w:r'); + while ifObj(prevRNode) do Begin + curLine ++; + prevRNode := prevRNode.PrevElement('w:r'); + End; + rmvN := 0; + nextRNode := tArr[i+iStep]['rNode']; + while ifObj(nextRNode) do Begin + rmvArr[rmvN++] := nextRNode; + nextRNode := nextRNode.NextElement('w:r'); + End; + rNode := NewParagraphNode.FirstChildElement('w:r'); + nI := 0; + rIndex := 0; + while ifObj(rNode) do Begin + cnt ++; + if cnt <= curLine then Begin + rmvArr[rmvN++] := rNode; + End + else Begin + tArr[i+iStep+nI]['pNode'] := NewParagraphNode; + tArr[i+iStep+nI]['rNode'] := rNode; + tArr[i+iStep+nI]['rIndex'] := rIndex++; + nr := new TRun(tArr[i+iStep+nI]['rNode']); + nI ++; + End; + rNode := rNode.NextElement('w:r'); + End; + //删除重复的run + for rmvN := 0 to length(rmvArr)-1 do begin + rmvArr[rmvN].Parent().DeleteChild(rmvArr[rmvN]); + End; + End; + TOfficeApi().Set('CodePage', CodePage); + + flag := ''; + code := nil; + tslArr := array(); + break; + End + else + flag := '[TSL]'; + End; + if Ord(c) > 127 then Begin + if ifstring(code) then + code += txt[k:k+1]; + k ++; + End + else if ifstring(code) then + code += c; + k ++; + wz ++; + End; + if length(tslArr) then Begin + //println('pIndex={},txt={},i={}',tArr[i]['pIndex'], txt, i); + if i and i < length(tArr) and tArr[i]['pIndex'] <> tArr[i+1]['pIndex'] then Begin + code += '\n'; + endPos ++; + End; + ind := length(tslArr) - 1; + if tslArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tslArr[ind]['rIndex'] <> tArr[i]['rIndex'] then + tslArr[ind + 1] := tArr[i]; + End; + i += iStep; + End; + return array(length(errArr), tslFuncCount, errArr); + End; + + Function ExecTsTag(docx, tagName, tagObj); + Begin + //表格 + t := array(); + tslTagCount := 0; + errArr := array(); + tArr := Tables(); + for i:=0 to length(tArr)-1 do Begin + col := tArr[i].Cols(); + row := tArr[i].Rows(); + for r:= 1 to row do Begin + for c:=1 to col do Begin + cell := tArr[i].Cell(r, c); + [err, cnt, err] := cell.ExecTsTag(docx, tagName, tagObj);//递归 + tslTagCount += cnt; + errArr union= err; + End; + End; + End; + + //文本框 + ps := Paragraphs(); + for i:=0 to length(ps)-1 do Begin + boxs := ps[i].TextBoxs(); + for j:=0 to length(boxs)-1 do Begin + [err, cnt, err] := boxs[j].ExecTsTag(docx, tagName, tagObj);//递归 + if cnt then + boxs[j].Apply(); + tslTagCount += cnt; + errArr union= err; + End; + End; + + //页脚、页眉 + sArr := Sections(); + tpArr := array('default','even','first'); + for i:=0 to length(sArr)-1 do Begin + for k, name in tpArr do Begin + h := sArr[i].Header(name); + if ifObj(h) then Begin + [err, cnt, err] := h.ExecTsTag(docx, tagName, tagObj);//递归 + tslTagCount += cnt; + errArr union= err; + End; + + f := sArr[i].Footer(name); + if ifObj(f) then Begin + [err, cnt, err] := f.ExecTsTag(docx, tagName, tagObj);//递归 + tslTagCount += cnt; + errArr union= err; + End; + End; + End; + + [err, cnt, err] := ExecTsTagImpl(docx, tagName, tagObj); + tslTagCount += cnt; + errArr union= err; + return array(length(errArr), tslTagCount, errArr); + End; + + Function ExecTsTagImpl(docx, tagName, tagObj); + Begin + tslTagCount := 0; + errArr := array(); + tagArr := array(); + tArr := TextArray(); + tagAttribute := ''; + tagStr := ''; + tagStatus := '';//array('','head', 'attribute', 'tail'); + tagHead := '[' + tagName; + tagTail := '[/' + tagName; + tmp := array(); + while i < length(tArr) do Begin + txt := ''; + iStep := 1; + if ifObj(tArr[i]['rNode']) then Begin + run := new TRun(tArr[i]['rNode']); + txt := run.Text(); + if class(TSXml).IsUtf8() then + txt := UTF8ToAnsi(txt); + End; + k := 1; + wz := 1; + txtLen := length(txt); + while k <= txtLen do Begin + c := txt[k]; + if c = ']' and (tagStatus = 'head' or tagStatus = 'attribute') and tagStr = tagHead then Begin //TAG头结束标志 + tagStr := ''; + tagArr := tArr[tmp['head-begin-paragraph']:i,:]; + wz++; + tagStatus := 'tail'; + tmp['head-end-paragraph'] := i; + tmp['head-end-pos'] := k++; + tmp['head-end-wz'] := wz; + tmp['head-end-txtlen'] := txtLen; + continue; + End; + case tagStatus of + '': + if c = '[' then Begin + tagStr := '['; + tmp['head-begin-paragraph'] := i; + tmp['head-begin-pos'] := k; + tmp['head-begin-wz'] := wz; + tmp['head-begin-txtlen'] := txtLen; + tagStatus := 'head'; + tagAttribute := ''; + End; + 'head': + if c = ' ' and tagStr = tagHead then Begin //找到TAG属性 + tagStatus := 'attribute'; + End + else if length(tagStr) < length(tagHead) and lowercase(c) = lowercase(tagHead[ length(tagStr) + 1 ]) then Begin + tagStr += tagHead[ length(tagStr) + 1 ]; + End + else //继续寻找TAG开始标志 + tagStatus := ''; + 'attribute': + tagAttribute += c; + 'tail': + if c=']' and tagStr = tagTail then Begin //查找到完整标签 + ind := length(tagArr) - 1; + if tagArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tagArr[ind]['rIndex'] <> tArr[i]['rIndex'] then Begin + ind ++; + tagArr[ind] := tArr[i]; + End; + + //[/tag]后 + if k < txtLen then Begin //后面分割为新的w:r + tArr[i]['rNode'] := run._duplicate_r(tArr[i]['rNode']); + run._adjust_r(tArr[i]['rNode'], wz, txtLen); + iStep := 0; + End; + //前[/tag] + tagInd := length(tagArr) - i + tmp['tail-begin-paragraph'] - 1; + if tmp['tail-begin-pos'] > 1 then Begin + nNode := run._duplicate_r(tagArr[tagInd]['rNode']); + run._adjust_r(tagArr[tagInd]['rNode'], 0, tmp['tail-begin-wz'] - 1); + tagArr[tagInd]['pNode'].DeleteChild(nNode); + tmp['tag-end'] := tagInd; + End + else if tmp['tail-begin-pos'] = 1 then Begin + tmp['tag-end'] := tagInd - 1; + End; + + //[tag]后 + firstNode := tagArr[0]['rNode']; + tagInd := length(tagArr) - i + tmp['head-end-paragraph'] - 1; + if tmp['head-end-pos'] < tmp['head-end-txtlen'] then Begin + oldNode := tagArr[tagInd]['rNode']; + tagArr[tagInd]['rNode'] := run._duplicate_r(oldNode); + run._adjust_r(tagArr[tagInd]['rNode'], tmp['head-end-wz'] - 1, tmp['head-end-txtlen']); + tmp['tag-beg'] := tagInd; + if tmp['head-begin-paragraph'] <> tmp['head-end-paragraph'] then + tagArr[tagInd]['pNode'].DeleteChild(oldNode); + End + else if tmp['head-end-pos'] = tmp['head-end-txtlen'] and tagInd then Begin + tmp['tag-beg'] := tagInd + 1; + End; + //前[tag] + if tmp['head-begin-pos'] > 1 then Begin + run._adjust_r(firstNode, 0, tmp['head-begin-wz'] - 1); + if firstNode = tagArr[0]['rNode'] then + tagArr[0]['rNode'] := nil; + End + else if tagInd=0 and tmp['tag-beg']=0 then + tagArr[0]['pNode'].DeleteChild(firstNode); + + //执行TAG逻辑 + r := array(); + for nI := 0 to length(tagArr)-1 do Begin + if not ifObj(tagArr[nI]['rNode']) then continue; + if nI >= tmp['tag-beg'] and nI <= tmp['tag-end'] then + r[length(r)] := tagArr[nI];//标签中间文字内容 + else Begin //删除标签 + tagArr[nI]['pNode'].DeleteChild(tagArr[nI]['rNode']); + node := tagArr[nI]['pNode'].FirstChildElement('w:r'); + if not ifObj(node) then Begin + tagArr[nI]['pNode'].Parent().DeleteChild(tagArr[nI]['pNode']); + End; + End; + End; + tagObj.Init(tagName, tagAttribute, r); + tagObj.Apply(); + tslTagCount++; + + tagStatus := ''; + tagArr := array(); + break; + End + else if length(tagStr) < length(tagTail) and lowercase(c) = lowercase(tagTail[ length(tagStr) + 1 ]) then Begin + tagStr += tagTail[ length(tagStr) + 1 ]; + if tagStr = '[' then Begin + tmp['tail-begin-paragraph'] := i; + tmp['tail-begin-pos'] := k; + tmp['tail-begin-wz'] := wz; + tmp['tail-begin-txtlen'] := txtLen; + End; + End + else //继续寻找TAG结束标志 + tagStr := ''; + End; + if Ord(c) > 127 then Begin + k ++; + End + k ++; + wz ++; + End; + if length(tagArr) then Begin + if i and i < length(tArr) and tArr[i]['pIndex'] <> tArr[i+1]['pIndex'] then Begin + endPos ++; + End; + ind := length(tagArr) - 1; + if tagArr[ind]['pIndex'] <> tArr[i]['pIndex'] or tagArr[ind]['rIndex'] <> tArr[i]['rIndex'] then + tagArr[ind + 1] := tArr[i]; + End; + i += iStep; + End; + return array(length(errArr), tslTagCount, errArr); + End; + + Function GetHeadingListImpl(docx, posOpt, UpperHeadingLevel, LowerHeadingLevel, numIds); + Begin + r := array(); + if ifObj(posOpt) then + pNode := posOpt.NextElement(); + else + pNode := node_.FirstChildElement(); + while ifObj(pNode) do Begin + name := pNode.GetName(); + if name = 'w:p' and not ifObj(pNode.FirstChildElement('w:sectPr')) then + begin + pStyle := class(TSXml).GetNode(pNode, "w:pPr/w:pStyle"); + level := nil; + if pStyle then + begin + styleId := pStyle.GetAttribute('w:val'); + if styleId <> '' and (obj := docx.StyleObject().GetStyleById(styleId)) and ifObj(obj) then + begin + level := getHeadingLevel(docx, obj); + end + end + else begin + level := class(TSXml).GetNode(pNode, "w:pPr/w:outlineLvl"); + if ifObj(level) then level := level.GetAttribute("w:val"); + end + if not ifnil(level) then + begin + iLevel := Class(TSXml).SafeStrToIntDef(level, -1); + if iLevel+1 >= UpperHeadingLevel and iLevel+1 <= LowerHeadingLevel then Begin + //统计数字项目编号 + p := new TParagraph(pNode); + text := p.Text(); + if text = "" then + begin + pNode := pNode.NextElement(); + continue; + end + numArr := array(); + numId := getNumPr('numId', docx, p); + ilvl := getNumPr('Level', docx, p); + if not ilvl then ilvl := 0; + if ifarray(numIds) then Begin + if ilvl >= 0 and ilvl < 10 then Begin + if not istable(numIds[numId]) then + numIds[numId] := array(0,0,0,0,0,0,0,0,0,0); + prev := numIds[numId, ilvl]; + if prev then Begin + for i:=ilvl+1 to 9 do + numIds[numId, i] := 0; + End; + numIds[numId, ilvl]++; + numArr := numIds[numId]; + End; + End; + r[ind]['Level'] := strtoint(level); + r[ind]['Paragraph'] := p; + r[ind]['Text'] := text; + r[ind]['numId'] := ifnumber(numId) ? integer(numId) : 0; //数字项目编号 + r[ind]['ilvl'] := ilvl; //级别 + r[ind]['numArr'] := numArr; //累加数字编码 + ind++; + End; + end + End + else if false and ifarray(numIds) and name = 'w:tbl' then Begin + tbl := TOfficeObj('TTable'); + tbl.Init(pNode); + rows := tbl.Rows(); + cols := tbl.Cols(); + for i:=1 to rows do Begin + for j:=1 to cols do Begin + cell := tbl.Cell(i, j); + if cell then [a, b] := cell.GetHeadingListImpl(docx, nil, UpperHeadingLevel, LowerHeadingLevel, numIds);//表格内递归查找,统计数字项目编号,但不显示在大纲中 + End; + End; + End; + pNode := pNode.NextElement(); + End; + + return r; + End; + + Function getNumPr(field, docx, p); + Begin + value := p.Format.NumPr.Value(field); + if value then return value; + styleId := p.Format.Value('StyleId', 1); + return getFieldByStyle(field, docx, docx.StyleObject().GetStyleById(styleid)); + End; + + Function getFieldByStyle(field, docx, obj); + Begin + if not ifObj(obj) then return ''; + numId := obj.pPr.numPr.Value(field); + if numId = '' then + begin + id := o.Value('BasedOn'); + return getNumIdByStyle(docx, docx.StyleObject().GetStyleById(id)); + end + return numId; + End; + + Function getHeadingLevel(docx, obj); + Begin + if not ifObj(obj) then return ''; + o := obj; + level := obj.HeadingLevel(); + if level = '' then + begin + id := o.Value('BasedOn'); + return getHeadingLevel(docx, docx.StyleObject().GetStyleById(id)); + end + return level; + End; + + + Function getPictureMaxId(); + Begin + id := 0; + pNode := node_.FirstChildElement('w:p'); + while ifObj(pNode) do Begin + rNode := pNode.FirstChildElement('w:r'); + while ifObj(rNode) do Begin + node := class(TSXml).GetNode(rNode, 'w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blibFill/a:blib'); + if ifObj(node) then Begin + v := node.GetAttribute('r:embed'); + if v <> '' then Begin + iVal := strtoint(v); + if iVal > id then id := iVal; + End; + End; + rNode := rNode.NextElement('w:r'); + End; + pNode := pNode.NextElement('w:p'); + End; + return id; + End; + + Function addPart(posOpt, o, flag); + Begin + node := posOpt; + if ifObj(posOpt) and not (posOpt is Class(XmlNode)) then + node := posOpt.Node(); + node := findNode(node, true); + if flag then nodeArr := o.node_.Marshal()[0]; + else nodeArr := o.Marshal(); + if ifObj(node) then Begin + o.node_ := node_.InsertAfterChild(node, nodeArr); //XmlNode节点对象或DocObject对象 + End + else if node = 0 then Begin + o.node_ := node_.InsertFirstChild(nodeArr); + End + else if node < 0 then Begin + o.node_ := node_.InsertEndChild(nodeArr); + End + else Begin + raise 'Invalid input param.'; + End; + TOfficeApi().Set('CurrentPosition', o.node_); + End; + + Function findNode(posOpt, b); + Begin + if not ifObj(lastParagraph_) then + return 0; + if ifObj(posOpt) then + return posOpt; + if b and posOpt = 0 then Begin + return 0; + End; + if posOpt < 0 then + return lastParagraph_; + + if ifInt(posOpt) then Begin + node := node_.FirstChildElement(); + ind := 0; + while ifObj(node) do Begin + name := node.GetName(); + if name = 'w:p' or name = 'w:tbl' then + ind ++; + if ind = posOpt + ifthen(b, 0, 1) then + return node; + node := node.NextElement(); + End; + End; + if b then + return lastParagraph_; + return 0; + End; + + Function getText(t); + Begin + if not ifstring(t) then return '' $ t; + return t; + txt := ReplaceStr(t, '\t', ''); + txt := ReplaceStr(txt, '\r\n', ''); + txt := ReplaceStr(txt, '\n', ''); + return txt; + End; + + Function _set_lastParagraph_(posOpt, node); + Begin + if not ifObj(lastParagraph_) then + lastParagraph_ := node; + else if ifInt(posOpt) and posOpt = -1 then + lastParagraph_ := node; + else if ifObj(posOpt) then Begin + posNode := posOpt; + if not (posOpt is Class(XmlNode)) then + posNode := posOpt.Node(); + if lastParagraph_.Eq(posNode) then Begin + _setLastParagraph(); + End; + End; + End; + + zipfile_; + lastParagraph_; + document_; +End; + +Type TDocHeaderFooter = Class(TDocumentBody) + Function Create(rid, obj, name); + Begin + rID_ := rid; + xmlObj_ := obj; + node := xmlObj_.FirstChildElement(name); + Index := -1; + Class(TDocumentBody).Create(node); + name_ := name; + End; + + ///添加页码 + ///fmt:string,页码格式(eg:"第 {0} 页,共 {1} 页") + ///font:字体格式 + Function AddPageNumber(fmt, font); + Begin + r := array(); + fmtLen := length(fmt); + txt := ''; + while i < fmtLen do Begin + if fmt[i+1] = '{' and i + 2 <= fmtLen and fmt[i+3] = '}' then Begin + if txt <> '' then + r[ cnt++ ] := txt; + r[ cnt++ ] := fmt[i+1:i+3]; + txt := ''; + i += 3; + End + else Begin + txt += fmt[i+1]; + i ++; + End; + End; + if txt <> '' then + r[ cnt++ ] := txt; + p := TOfficeObj('TParagraph'); + class(TSXml).CopyRprFormat(p.pPr.rPr, font); + for i:=0 to length(r)-1 do Begin + run := p.AddRun(); + if r[i] = '{0}' then Begin //页码 + run.fldCharType := 'begin'; + class(TSXml).CopyRprFormat(run.rPr, font); + PageNo := p.AddRun(); + PageNo.InstrText := ' PAGE \\* MERGEFORMAT '; + PageNo.InstrTextSpace := 'preserve'; + class(TSXml).CopyRprFormat(PageNo.rPr, font); + run := p.AddRun(); + run.fldCharType := 'end'; + class(TSXml).CopyRprFormat(run.rPr, font); + End + else if r[i] = '{1}' then Begin //总页数 + run.fldCharType := 'begin'; + class(TSXml).CopyRprFormat(run.rPr, font); + TotalPageNo := p.AddRun(); + TotalPageNo.InstrText := ' NUMPAGES \\* MERGEFORMAT '; + TotalPageNo.InstrTextSpace := 'preserve'; + class(TSXml).CopyRprFormat(TotalPageNo.rPr, font); + run := p.AddRun(); + run.fldCharType := 'end'; + class(TSXml).CopyRprFormat(run.rPr, font); + End + else Begin + run.SetText( r[i] ); + class(TSXml).CopyRprFormat(Run.rPr, font); + End; + End; + return AddParagraph(p, -1, nil); + End; + + rId_:integer; + xmlFileName_:string; + root_; + xmlObj_; +End; + +Type TCols = Class(TColsImpl) + Function AddCol(); + Begin + o := new TCol(); + NewChildNode( array("field":"", "name":"w:col", "obj":o, "attrEx":"", "nodeType":"") ); + return o; + End; + +End; + +Type TDocSection = Class(DocObject, TDocSectionImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Create(node, -1, nil); + End; + + Function Create(node, index, z);overload; + Begin + Index_ := index; + name_ := 'w:sectPr'; + node_ := node; + zipfile_ := z; + Class(TDocSectionImpl).Create(nil, name_); + InitRootNode(node); + End; + + ///返回指定页眉 + ///type:页眉类型,(default、even、first) + ///default, Header for odd pages or all if no even header. + ///first, Header for first page of section. + ///even, Header for even pages of recto/verso section. + Function Header(type); + Begin + return _getHeaderFooter('w:headerReference', type); + End; + + ///返回指定页脚 + ///type:页眉类型,(default、even、first) + ///default, Header for odd pages or all if no even header. + ///first, Header for first page of section. + ///even, Header for even pages of recto/verso section. + Function Footer(type); + Begin + return _getHeaderFooter('w:footerReference', type); + End; + + ///添加页眉 + ///type:页眉类型,(default、even、first) + ///default, Header for odd pages or all if no even header. + ///first, Header for first page of section. + ///even, Header for even pages of recto/verso section. + Function AddHeader(type); + Begin + return _AddHeaderFooter('header', (ifNil(type) or type = '') ? 'default' : type); + End; + + ///添加页脚 + ///type:页眉类型,(default、even、first) + ///default, Header for odd pages or all if no even header. + ///first, Header for first page of section. + ///even, Header for even pages of recto/verso section. + Function AddFooter(type); + Begin + return _AddHeaderFooter('footer', (ifNil(type) or type = '') ? 'default' : type); + End; + + Function _AddHeaderFooter(headerFooter, hfType); + Begin + if headerFooter = 'header' then Begin + name := 'w:hdr'; + type := 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header'; + ContentType := 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'; + obj := _getHeaderFooter('w:headerReference', hfType); //页眉已经存在 + fileContent := ''; + End + else Begin + name := 'w:ftr'; + type := 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer'; + ContentType := 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'; + obj := _getHeaderFooter('w:footerReference', hfType); //页脚已经存在 + fileContent := ''; + End + if ifObj(obj) then return obj; + rels := zipfile_.Get('word/_rels/document.xml.rels'); + [rid, target] := class(TSXml).FindRelationshipRid(rels, '');//最大rId + rid ++; + files := sselect ['FileName'] from zipfile_.Files() where AnsiStartsText('word/' $ headerFooter, ['FileName']) end; + fid := length(files) + 1;//文件ID号 + target := headerFooter $ fid $ '.xml'; + class(TSXml).AddRelationshipRid(rels, target, type, 'rId'$rid, nil);//添加rId + PartName := '/word/' $ headerFooter $ fid $ '.xml'; + contentXml := zipfile_.Get('[Content_Types].xml'); + class(TSXml).AddOverrideContentType(contentXml, partName, contentType);//添加Contet_Types + fname := 'word/' $ headerFooter $ fid $ '.xml'; + zipfile_.Add(fname, fileContent);//创建页脚、页眉文件 + node := node_.InsertFirstChild('element', headerFooter = 'header' ? 'w:headerReference' : 'w:footerReference'); + node.SetAttribute('w:type', hfType); + node.SetAttribute('r:id', 'rId'$rid); + if hfType = 'first' then Begin + docGridNode := node_.FirstChildElement('w:docGrid'); + titlePg := node_.FirstChildElement('w:titlePg'); + if not ifObj(titlePg) then Begin + if ifObj(docGridNode) then + titlePg := node_.InsertBeforeChild(docGridNode,'element','w:titlePg'); + else + titlePg := node_.InsertEndChild('element','w:titlePg'); + End; + End; + + if hfType = 'even' then Begin + settingsXml := zipfile_.Get('word/settings.xml'); + if ifObj(settingsXml) then Begin + evenObj := settingsXml.FirstChildElement('w:settings').FirstChildElement('w:evenAndOddHeaders'); + if not ifObj(evenObj) then + evenObj := settingsXml.FirstChildElement('w:settings').InsertFirstChild('element','w:evenAndOddHeaders'); + evenObj.SetAttribute('w:val', 1); + End; + End; + return new TDocHeaderFooter(rid, zipfile_.Get(fname), name);//返回页脚、页眉对象 + End; + + Function _getRid(key, type); + Begin + if ifNil(type) or type = '' then + type := 'default'; + node := node_.FirstChildElement(key); + while ifObj(node) do Begin + name := node.GetName(); + if name = key then Begin + if type = node.GetAttribute('w:type') then + return node.GetAttribute('r:id'); + End; + node := node.NextElement(key); + End; + return ''; + End; + + Function _getHeaderFooter(key, type); + Begin + rid := _getRid(key, type); + if rid='' then return nil; + rels := zipfile_.Get('word/_rels/document.xml.rels'); + theNode := class(TSXml).FindRelationship(rels, rid); + if not ifObj(theNode) then + return nil; + fname := 'word/' $ theNode.GetAttribute('Target'); + xml := zipfile_.Get(fname); + if ifObj(xml) then + return new TDocHeaderFooter(rid, xml, key = 'w:headerReference' ? 'w:hdr' : 'w:ftr'); + return nil; + End; + + Index_:integer; + zipfile_; //压缩文件对象 +End; + +//node_ -> w:p/w:r/mc:AlternateContent/mc:Choice/mc:Fallback/w:pict/v:shape/v:textbox/w:txbxContent +Type TTextBox = Class(TDocumentBody, TTextBoxImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Class(TTextBoxImpl).Create(nil, 'w:txbxContent'); + Class(TDocumentBody).Create(node); + name_ := 'w:txbxContent'; + InitRootNode(node); + End; + + Function Create(pNode, name);overload; + Begin + Create(nil); + End; + + Function Init(pNode, nodeEx); + Begin + pNode_ := pNode; + NodeEx_ := nodeEx; + End; + + Function Apply();override; + Begin + if ifObj(NodeEx_) then Begin + data := node_.Marshal(); + NodeEx_.DeleteChildren(); + class(TSXml).UpdateNode(NodeEx_, data[0]['attributes'], data[0]['children']); + End; + End; + + Function Clear(); + Begin + if ifObj(node_) then node_.DeleteChildren(); + End; + + pNode_;// + NodeEx_;//w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/wps:txbxContent +End; + +//w:tr +Type TRow = Class(DocObject, TwTr) + Function Create(node); + Begin + node_ := node; + Class(TwTr).Create(nil, 'w:tr'); + End; + + Property Format read readFormat; + Function readFormat(); + Begin + return TrPr; + End; + + Property FormatEx read readFormatEx; + Function readFormatEx(); + Begin + return tblPrEx; + End; + + Function Apply();virtual; + Begin + arr := Marshal(); + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + End; +End; + +Type TFootnote = Class(TDocumentBody, TFootnoteImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + Class(TDocumentBody).Create(node); + Create(node, 'w:footnote'); + node_ := node; + End; + + Function Create(pNode, name);overload; + Begin + Class(TFootnoteImpl).Create(nil, name); + InitRootNode(pNode); + End; + + node_; +End; + +Type TFootnotes = Class + Function InitFootnotes(zip); + Begin + zip_ := zip; + file := 'word/footnotes.xml'; + footnotesXml_ := zip.Get(file); + idMap_ := array(); + maxId_ := 0; + if not ifObj(footnotesXml_) then + begin + content := ''; + zip_.Add(file, content); + footnotesXml_ := zip.Get(file); + // content_type + ctXml := zip_.Get('[Content_Types].xml'); + class(TSXml).AddOverrideContentType(ctXml, '/word/footnotes.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'); + // document.xml.rels + rels := zip_.Get('word/_rels/document.xml.rels'); + [maxRid, target, id] := class(TSXml).FindRelationshipRid(rels, ''); + maxRid++; + class(TSXml).AddRelationshipRid(rels, 'footnotes.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes', 'rId' $ maxRid); + end + footnotesNode_ := footnotesXml_.FirstChildElement("w:footnotes"); + node := footnotesNode_.FirstChildElement('w:footnote'); + while ifObj(node) do + begin + obj := new TFootnote(node); + id := obj.Value('Id', true); + idMap_[id] := obj; + id := StrToIntDef(id, 0); + if id > maxId_ then maxId_ := id; + node := node.NextElement(); + end + End; + + Function Add(); + Begin + node := footnotesNode_.InsertEndChild('element', 'w:footnote'); + node.SetAttribute('w:id', ++maxId_); + obj := new TFootnote(node); + obj.Id := maxId_; + idMap_[maxId_] := obj; + return obj; + End; + + Function GetFootnote(id); + Begin + return idMap_[id]; + End; + + Function CopyFootnote(obj); + Begin + marshal := obj.Root().Marshal()[0]; + node := footnotesNode_.InsertEndChild(marshal); + node.SetAttribute('w:id', ++maxId_); + obj := new TFootnote(node); + obj.Id := maxId_; + idMap_[maxId_] := obj; + return obj; + End; + +private + zip_; + footnotesXml_; + footnotesNode_; + idMap_; + maxId_; +End; + +//w:tc +Type TCell = Class(TDocumentBody, TWTc) + Function Create();overload; + Begin + Create(nil); + End; + Function Create(node);overload; + Begin + Class(TDocumentBody).Create(node); + Create(node, 'w:tc'); + End; + + Function Create(pNode, name);overload; + Begin + Class(TWTc).Create(nil, 'w:tc'); + InitRootNode(pNode); + name_ := 'w:tc'; + mergeSpan_ := 0; + pPr_ := new TwpPr(); + End; + + Property Format read readFormat; + Function readFormat(); + Begin + return TcPr; + End; + + Property PFormat read readPFormat; + Function readPFormat(); + Begin + return pPr_; + End; + + Function Apply(); override; + Begin + arr := Marshal(); + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + + arr := pPr_.Marshal(); + if length(arr['attributes']) or length(arr['children']) then Begin + pNode := node_.FirstChildElement('w:p'); + while ifObj(pNode) do Begin + pPr := class(TSXml).GetNode(pNode, 'w:pPr', 'first'); + class(TSXml).UpdateNode(pPr, arr['attributes'], arr['children']); + pNode := pNode.NextElement(); + End; + End; + End; + + ///添加文字 + Function SetText(txt); + Begin + if not ifString(txt) then + lines := array('' $ txt); + else + lines := str2array(txt, '\n'); + for i:=0 to length(lines)-1 do Begin + newp := new TParagraph(); + newp.pPr.rPr.Lang := 'en-US'; + newp.pPr.rPr.eastAsia := 'zh-CN'; + newp.Run.rPr.Lang := 'en-US'; + newp.Run.rPr.eastAsia := 'zh-CN'; + newp.Run.SetText( lines[i] ); + NewChildNode( array("field":"", "name":"w:p", "obj":newp, "attrEx":"", "nodeType":"") ); + End; + if not istable(lines) then + P.Run.T := ''; + End; + + Function Clear(); + Begin + node := node_.FirstChildElement('w:p'); + while ifObj(node) do Begin + n := node.NextElement(); + if ind = 0 then + node.DeleteChildren(); + else + node_.DeleteChild(node); + ind++; + node := n; + End; + End; + + Function Row(); + Begin + return new TRow(node_.Parent()); + End; + + Function Append(c); + Begin + ps := c.Parts(); + for i:=0 to length(ps)-1 do Begin + if not ps[i].node_.GetName() in array('w:p', 'w:tbl') then continue; + data := ps[i].node_.Marshal(); + w := node_.InsertEndChild(data[0]); + End; + End; + + mergeSpan_:integer; + pPr_;//段落格式 +End; + +//w:tbl +Type TTable = Class(DocObject, TTableImpl) + Function Create();overload; + Begin + Create(nil); + End; + + Function Create(node);overload; + Begin + name_ := 'w:tbl'; + Class(TTableImpl).Create(nil, 'w:tbl'); + if ifObj(node) then + Init(node); + End; + + Function Root();override; + Begin + return node_; + End; + + Function Init(node); + Begin + node_ := node; + cells_ := array(); + iCol_ := 0; + row := node.FirstChildElement('w:tr'); + while ifObj(row) do Begin + col := row.FirstChildElement('w:tc'); + iCol := 0; + while ifObj(col) do Begin + //c := new TCell(col); + cells_[iRow, iCol] := array(col, 0); + iCol ++; + mergeSpan := _getVSpan(col);//合并单元格 + if mergeSpan > 0 then Begin + //c.mergeSpan_ := mergeSpan; + cells_[iRow, iCol, 1] := mergeSpan; + for j:=1 to mergeSpan-1 do Begin + cells_[iRow, iCol] := nil; + iCol ++; + End; + End; + if iCol > iCol_ then iCol_ := iCol; + col := col.NextElement('w:tc'); + End; + iRow ++; + row := row.NextElement('w:tr'); + End; + InitRootNode(node); + End; + + Function GetCell(r, c); + Begin + return cells_[r-1, c-1]; + End; + + ///设置表格数据 + ///data: table,数据表 + ///[includeHeader: bool] 是否包括表头,默认FALSE + ///[includeIndex: bool] 是否自动添加索引号,默认FALSE + Function SetData(docx, data, includeHeader, includeIndex); + Begin + if not IsTable(data) then + raise "Invalid Data."; + [rowcount,colcount] := mSize(data);//一维数组 + if colcount = 0 then + data := array(data); + fields := FieldNames(data); + if IsTable(fields) then Begin + r := nils(length(data),length(fields)); + r[:,:] := data; + data := r; + End; + if includeIndex then Begin + n := length(data)-1; + r := array(0->n); + data := `r | data; + End; + if includeHeader and IsTable(fields) then Begin + if includeIndex then + fields := array("Index") union fields; + data := array(fields) union data; + End; + Data_ := data; + TblPr.StyleId := _GetStyle(docx, 'normaltable'); + TblPr.Width := 0; + TblPr.WidthType := 'auto'; + //TblPr.Borders.Top.Val := 'single'; + //TblPr.Borders.Left.Val := 'single'; + //TblPr.Borders.Bottom.Val := 'single'; + //TblPr.Borders.Right.Val := 'single'; + //TblPr.Borders.InsideH.Val := 'single'; + //TblPr.Borders.InsideV.Val := 'single'; + //TblPr.CellMar.Top := 0; + //TblPr.CellMar.Left := 108; + //TblPr.CellMar.Bottom := 0; + //TblPr.CellMar.Right := 108; + //TblPr.CellMar.TopType := 'dxa'; + //TblPr.CellMar.LeftType := 'dxa'; + //TblPr.CellMar.BottomType := 'dxa'; + //TblPr.CellMar.RightType := 'dxa'; + //TblPr.FirstColumn := 1; + //TblPr.FirstRow := 1; + //TblPr.LastColumn := 0; + //TblPr.LastRow := 0; + //TblPr.NoVBand := 1; + //TblPr.NoHBand := 0; + //TblPr.Val := '04A0'; + + width := getBlockWidth(docx); + [rowCount, cnt] := MSize(data); + colCount_ := cnt; + colWidth_ := colCount_ ? integer(width / colCount_) : 0; + gridArr := array(); + for i:=0 to colCount_-1 do Begin + gcol := new TwGridCol(); + gcol.W := colWidth_; + gridArr union= array(('name':'w:gridCol','obj':gcol,'attrEx':'','nodeType':'','attrName':'')); + End; + TblGrid.GridCol := gridArr; + End; + + Function _GetStyle(obj, id); + Begin + style := obj.StyleObject().GetStyleById(id); + if not ifObj(style) then Begin + style := obj.StyleObject().AddDefaultStyle(id); + End; + return style.StyleId; + End; + + Property Format read readFormat; + Function readFormat(); + Begin + return TblPr; + End; + + Property Paragraph read readParagraph; + Function readParagraph(); + Begin + if not ifObj(paragraph_) then + paragraph_ := new TParagraph(); + return paragraph_; + End; + + Property FormatEx read readFormatEx; + Function readFormatEx(); + Begin + return TblPr.tblpPr; + End; + + ///修改表格属性 + Function Apply(); override; + Begin + arr := Marshal(); + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + End; + + ///列数 + Function Cols(); + Begin + return iCol_; + End; + + ///行数 + Function Rows(); + Begin + return length(cells_); + End; + + ///获取单元格 + Function Cell(row, col); + Begin + if row > length(cells_) then return nil; + c := cells_[row-1, col-1]; + if ifNil(c) then return nil; + cellObj := new TCell(c[0]); + cellObj.mergeSpan_ := c[1]; + return cellObj; + End; + + ///设置列宽 + Function ColumnWidth(n, wth); + Begin + if n >0 and n <= length(TblGrid.GridCol) then + TblGrid.GridCol[n-1]['obj'].W := wth; + End; + + /// 设置行高 + Function RowHeight(row, height); + Begin + if row <= 0 or row > Rows() then return; + node := _getRowNode(row - 1); + node := class(TSXml).GetNode(node, 'w:trPr/w:trHeight', 'end'); + node.SetAttribute('w:hRule', 'exact'); + node.SetAttribute('w:val', height); + End; + + Function Height(row); + Begin + if row <= 0 or row > Rows() then return nil; + node := _getRowNode(row - 1); + obj := new TwTr(); + obj.InitRootNode(node); + return obj.TrPr.Value('Height'); + End; + + Function Width(col); + Begin + obj := Cell(1, col); + return obj.Format.Value('Width'); + End; + + ///合并单元格 + ///del: bool,是否删除其它单元格内容(只保留左上单元格内容) + Function Merge(top, left, bottom, right, del);overload; + Begin + // + // + rowCount := Rows(); + if left > right or top > bottom or left > iCol_ or top > rowCount or (left = right and top = bottom) then + return 'Invalid input param.'; + //合并其它单元格 + [left2, right2, top2, bottom2] := array(left, right, top, bottom); + //println('merge(left2, right2, top2, bottom2)={}',array(left2, right2, top2, bottom2)); + for i:=left to right do Begin + if top > 1 then Begin + c1 := Cell(top - 1, i); + c2 := Cell(top, i); + if (c2 = nil or c2.mergeSpan_ > 0) and (c1 = nil or c1.mergeSpan_ > 0) then Begin + top2 := _getTop(top - 1, i, top2); + End; + End; + + if bottom < rowCount then Begin + c1 := Cell(bottom, i); + c2 := Cell(bottom + 1, i); + if (c2 = nil or c2.mergeSpan_ > 0) and (c1 = nil or c1.mergeSpan_ > 0) then Begin + bottom2 := _getBottom(bottom + 1, rowCount, i, bottom2); + End; + End; + End; + for i:=top to bottom do Begin + if left > 1 then Begin + c1 := Cell(i, left - 1); + c2 := Cell(i, left); + if c2 = nil and (c1 = nil or c1.mergeSpan_ > 0) then + left2 := _getLeft(i, left - 1, left2); + End; + + if right < iCol_ then Begin + c1 := Cell(i, right); + c2 := Cell(i, right + 1); + if c2 = nil and (c1 = nil or c1.mergeSpan_ > 0) then + right2 := _getRight(i, right + 1, right2); + End; + End; + //println('merge(left2, right2, top2, bottom2)={}\n',array(left2, right2, top2, bottom2)); + val := right2 - left2 + 1; + theCell := Cell(top2, left2); + for row:=top2 to bottom2 do Begin + c := Cell(row, left2); + c.mergeSpan_ := val; + gridSpan := class(TSXml).GetNode(c.node_, 'w:tcPr/w:gridSpan', true); + gridSpan.SetAttribute('w:val', val); + node := class(TSXml).GetNode(c.node_, 'w:tcPr/w:vMerge', true); + node.SetAttribute('w:val', row=top2 ? 'restart' : 'continue'); + if row <> top2 then Begin + if not del then + theCell.Append(c); + c.Clear(); + End; + + for col:=left2 + 1 to right2 do Begin + c := Cell(row, col); + if ifObj(c) then Begin + if not del then + theCell.Append(c); + c.node_.Parent().DeleteChild(c.node_); + cells_[row-1, col-1] := nil; + End; + End; + End; + + return 'ok'; + End; + + ///合并单元格 + ///hcell: string,左上角坐标,eg: 'B2' + ///vcell: string,右下角坐标,eg: 'C4' + ///del: bool,是否删除其它单元格内容(只保留左上单元格内容) + Function Merge(hCell, vCell, del);overload; + Begin + [err1, left, top] := CellNameToCoordinates(hCell); + [err2, right, bottom] := CellNameToCoordinates(vCell); + if err1 or err2 then + return 'Invalid input Coordinates.'; + return Merge(top, left, bottom, right, del); + End; + + ///删除单元格 + ///row: int, 行 + ///col: int, 列 + ///[cellshift]: int, 默认1。0:删除单元格下方内容上移,1:删除单元格右侧单元格左移 + ///row或col其中一个为nil时,删除某行或某列,如(1, nil),删除第一行 + Function DeleteCell(row, col, cellshift); + Begin + if ifnil(cellshift) then cellshift := 1; + if ifnumber(row) and ifnil(col) then + begin + node := _getRowNode(row - 1); + if ifObj(node) then node_.DeleteChild(node); + for i:=row-1 to length(cells_)-2 do + cells_[i] := cells_[i + 1]; + reindex(cells_, array(length(cells_)-1 : nil)); + end + else if ifnil(row) and ifnumber(col) then + begin + for r:=1 to length(cells_) do + DeleteCell(r, col); + iCol_--; + end + else begin + c := cells_[row-1, col-1]; + if not c then return; + node := _getRowNode(row - 1); + if cellshift then + begin + node.DeleteChild(c[0]); + for i:=col-1 to iCol_ - 1 do + cells_[row-1, i] := cells_[row-1, i+1]; + cells_[row-1, iCol_-1] := nil; + end + else begin + r := row; + len := length(cells_); + while r < len and ifObj(node) do + begin + tcell := cells_[r, col-1]; + if tcell then + begin + new_node := node.InsertAfterChild(c[0], tcell[0].Marshal()[0]); + node.DeleteChild(c[0]); + cells_[row-1, col-1, 0] := new_node; + end + c := tcell; + ++r; + node := node.NextElement(); + end + if c then + begin + p := c[0].FirstChild('w:p'); + c[0].DeleteChildren(); + c[0].InsertEndChild('element', 'w:p'); + end + end + end + End; + + ///设置表格样式ID + ///docx: TSDocxFile对象 + ///styleId: 表格样式ID + Function SetStyleById(docx, styleId); + Begin + ret := array(); + _getTblStylePr(docx, styleId, ret); + tblPr.StyleId := styleId; + Apply(); + for i:=0 to length(ret)-1 do + begin + cnf := TOfficeObj('TwCnfStyle'); + cnf.Val := 000000000000; + cnf.FirstRow := 0; + cnf.LastRow := 0; + cnf.FirstColumn := 0; + cnf.LastColumn := 0; + cnf.OddVBand := 0; + cnf.EvenVBand := 0; + cnf.OddHBand := 0; + cnf.EvenHBand := 0; + cnf.FirstRowFirstColumn := 0; + cnf.FirstRowLastColumn := 0; + cnf.LastRowFirstColumn := 0; + cnf.LastRowLastColumn := 0; + + case ret[i] of + 'firstRow': + begin + node := _getRowNode(0); + trPr := node.FirstChild('w:trPr'); + twtrpr := TOfficeObj('TwTrPr'); + twtrpr.InitRootNode(trPr); + cnf.Val := 100000000000; + cnf.FirstRow := 1; + twtrpr.CnfStyle := cnf; + twtrpr.Update(); + end + 'lastRow': + begin + node := _getRowNode(Rows()-1); + trPr := node.FirstChild('w:trPr'); + twtrpr := TOfficeObj('TwTrPr'); + twtrpr.InitRootNode(trPr); + cnf.Val := 010000000000; + cnf.LastRow := 1; + twtrpr.CnfStyle := cnf; + twtrpr.Update(); + end + end; + end + End; + + Function _getTblStylePr(docx, id, ret); + Begin + style_obj := docx.StyleObject().GetStyleById(id); + if not ifObj(style_obj) then return; + tbl_style_pr := style_obj.Root().FirstChild('w:tblStylePr'); + while ifObj(tbl_style_pr) do + begin + wtype := tbl_style_pr.GetAttribute('w:type'); + ret[length(ret)] := wtype; + tbl_style_pr := tbl_style_pr.NextElement('w:tblStylePr'); + end + base := style_obj.Value('BasedOn'); + _getTblStylePr(docx, base, ret); + End; + + Function _getRowNode(row); + Begin + node := node_.FirstChild('w:tr'); + while row and ifObj(node) do + begin + row--; + node := node.NextElement('w:tr'); + end + return node; + End; + + Function _getLeft(row, iCol, left2); + Begin + for i:=iCol downto 1 do Begin + c := Cell(row, i); + if ifObj(c) then Begin + if i < left2 then + left2 := i; + break; + End; + End; + return left2; + End; + + Function _getRight(row, iCol, right2); + Begin + for i:=iCol to iCol_ do Begin + c := Cell(row, i); + if ifObj(c) then + break; + if i > right2 then + right2 := i; + End; + return right2; + End; + + Function _getTop(top, iCol, top2); + Begin + for i:=top downto 1 do Begin + c := Cell(i, iCol); + if ifObj(c) and c.mergeSpan_ < 1 then Begin + break; + End; + if i < top2 then + top2 := i; + End; + return top2; + End; + + Function _getBottom(bottom, rowCount, iCol, bottom2); + Begin + for i:=bottom to rowCount do Begin + c := Cell(i, iCol); + if ifObj(c) and c.mergeSpan_ < 1 then Begin + break; + End; + if i > bottom2 then + bottom2 := i; + End; + return bottom2; + End; + + Function _getVSpan(node); + Begin + vMerge := class(TSXml).GetNode(node, 'w:tcPr/w:vMerge'); + if ifObj(vMerge) and vMerge.GetAttribute('w:val') in array('restart', 'continue') then Begin + nSpan := class(TSXml).GetNode(node, 'w:tcPr/w:gridSpan'); + if ifObj(nSpan) then Begin + return strtoint(nSpan.GetAttribute('w:val')); + End; + End; + return -1; + End; + + Function getBlockWidth(docx); + Begin + sectPr := docx.Body().node_.FirstChildElement('w:sectPr'); + try + width := sectPr.FirstChildElement('w:pgSz').GetAttribute('w:w'); + left := sectPr.FirstChildElement('w:pgMar').GetAttribute('w:left'); + right := sectPr.FirstChildElement('w:pgMar').GetAttribute('w:right'); + return strtoint(width) - strtoint(left) - strtoint(right); + except + End; + return strtoint(width); + End; + + iCol_:integer; + cells_; + Data_; + colCount_; + colWidth_; + paragraph_;//缺省单元格段落格式、字体格式 +End; + +Type TCoreProperties = Class(DocObject) + Property Author read readAuthor write writeAuthor; + Property Category read readCategory write writeCategory; + Property Description read readDescription write writeDescription; + Property Subject read readSubject write writeSubject; + Property Title read readTitle write writeTitle; + Property Version read readVersion write writeVersion; + Property Rversion read readRversion write writeRversion; + Property KeyWords read readKeyWords write writeKeyWords; + Property Created read readCreated write writeCreated; + Property Modified read readModified write writeModified; + Property LastModifiedBy read readLastModifiedBy write writeLastModifiedBy; +private + Function readAuthor(); + Begin + return propValue('dc:creator'); + End; + + Function readCategory(); + Begin + return propValue('cp:category'); + End; + + Function readDescription(); + Begin + return propValue('dc:description'); + End; + + Function readSubject(); + Begin + return propValue('dc:subject'); + End; + + Function readTitle(); + Begin + return propValue('dc:title'); + End; + + Function readVersion(); + Begin + return propValue('cp:version'); + End; + + Function readRversion(); + Begin + return propValue('cp:rversion'); + End; + + Function readKeyWords(); + Begin + return propValue('cp:keywords'); + End; + + Function readLastModifiedBy(); + Begin + return propValue('cp:lastModifiedBy'); + End; + + Function readCreated(); + Begin + return propValue('dcterms:created'); + End; + + Function readModified(); + Begin + return propValue('dcterms:modified'); + End; + + Function propValue(k); + Begin + node := class(TSXml).GetNode(node_, k); + if not ifObj(node) then return ''; + return class(TSXml).Utf8ToCurCodePage( node.GetText() ); + End; + + Function propNode(k); + Begin + n := node_.FirstChildElement(k); + if ifObj(n) then return n; + return node_.InsertEndChild('element', k); + End; + + Function writeAuthor(v); + Begin + return propNode('dc:creator').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeCategory(v); + Begin + return propNode('cp:category').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeDescription(v); + Begin + return propNode('dc:description').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeSubject(v); + Begin + return propNode('dc:subject').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeTitle(v); + Begin + return propNode('dc:title').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeVersion(v); + Begin + return propNode('cp:version').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeRversion(v); + Begin + return propNode('cp:rversion').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeKeyWords(v); + Begin + return propNode('cp:keywords').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeLastModifiedBy(v); + Begin + return propNode('cp:lastModifiedBy').SetValue(class(TSXml).CurCodePageToUtf8(v)); + End; + + Function writeCreated(v); + Begin + return propNode('dcterms:created').SetValue(class(TSXml).GetDatetimeStr(v)); + End; + + Function writeModified(v); + Begin + return propNode('dcterms:modified').SetValue(class(TSXml).GetDatetimeStr(v)); + End; +End; + +//w:latentStyles +// Attributes(w:name、w:count、w:defLockedState、w:defQFormat、w:defSemiHidden、w:defUIPriority、w:defUnhideWhenUsed) + + +//w:style +// 'w:name', 'w:aliases', 'w:basedOn', 'w:next', 'w:link', +// 'w:autoRedefine', 'w:hidden', 'w:uiPriority', 'w:semiHidden', +// 'w:unhideWhenUsed', 'w:qFormat', 'w:locked', 'w:personal', +// 'w:personalCompose', 'w:personalReply', 'w:rsid', 'w:pPr', 'w:rPr', +// 'w:tblPr', 'w:trPr', 'w:tcPr', 'w:tblStylePr' +Type TDocxStyle = Class(TDocxStyleImpl) + Function Create(); overload; + Begin + create(nil); + End; + + Function Create(node); overload; + Begin + Init(node); + Class(TDocxStyleImpl).Create(nil, 'w:style'); + End; + + Function Init(node); + Begin + if ifObj(node) then Begin + node_ := node; + wType := node.GetAttribute('w:type'); + styleId := node.GetAttribute('w:styleId'); + nameObj := node.FirstChildElement('w:name'); + if ifObj(nameObj) then + Name := nameObj.GetAttribute('w:val'); + InitRootNode(node); + End; + End; + + ///显示大纲级别 + Function HeadingLevel(); + Begin + node := class(TSXml).GetNode(node_, 'w:pPr/w:outlineLvl'); + if ifObj(node) then + return node.GetAttribute('w:val'); + return ''; + End; + + Function ReadPprFormat(); + Begin + if ifObj(pPr_) then + return pPr_; + pPr_ := Class(TSXml).ReadPprFormat(node_); + return pPr_; + End; + + Function ReadRprFormat(); + Begin + if ifObj(rPr_) then + return rPr_; + rPr_ := Class(TSXml).ReadRprFormat(node_); + return rPr_; + End; + + Function Apply(); + Begin + if ifObj(rPr_) then Begin + arr := rPr_.Marshal(); + if length(arr['attributes']) or length(arr['children']) then Begin + class(TSXml).UpdateNode(rPr_.Root(), arr['attributes'], arr['children']); + End; + End; + + if ifObj(pPr_) then Begin + arr := pPr_.Marshal(); + if length(arr['attributes']) or length(arr['children']) then Begin + class(TSXml).UpdateNode(pPr_.Root(), arr['attributes'], arr['children']); + End; + End; + + arr := self.Marshal(); + if length(arr['attributes']) or length(arr['children']) then Begin + class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']); + End; + End; + + node_; + pPr_; + rPr_; +End; + +Type TNumStyle = Class(TNumStyleImpl) + Function Create(); overload; + Begin + create(nil); + End; + + Function Create(node); overload; + Begin + Init(node); + Class(TNumStyleImpl).Create(nil, 'w:num'); + End; + + Function Init(node); + Begin + if ifObj(node) then Begin + node_ := node; + abstractNumId := node.GetAttribute('w:abstractNumId'); + typeNode := node.FirstChildElement('w:multiLevelType'); + if ifObj(typeNode) then + multiLevelType := typeNode.GetAttribute('w:val'); + fmtNode := class(TSXml).GetNode(node, 'w:lvl/w:numFmt'); + if ifObj(fmtNode) then + numFmt := fmtNode.GetAttribute('w:val'); + InitRootNode(node); + End; + End; + + Function Root();override; + Begin + return node_; + End; + + ///数字项目编号样式ID + Function Id(); + Begin + return abstractNumId; + End; + + ///数字项目编号字符串 + Function GetText(ilvl, arr); + Begin + if numFmt = 'bullet' then + return ''; + if not ifarray(levels_) then Begin + levels_ := array(); + node := node_.FirstChildElement('w:lvl'); + while ifObj(node) do Begin + startObj := node.FirstChildElement('w:start'); + fmtObj := node.FirstChildElement('w:numFmt'); + textObj := node.FirstChildElement('w:lvlText'); + start := ifObj(startObj) ? Class(TSXml).SafeStrToIntDef(startObj.GetAttribute('w:val'), 1) : 1; + fmt := ifObj(fmtObj) ? fmtObj.GetAttribute('w:val') : ''; + lvlText := ifObj(textObj) ? textObj.GetAttribute('w:val') : ''; + levels_[length(levels_)] := array('node':node, 'text':lvlText, 'numFmt':fmt, 'start':start); + node := node.NextElement('w:lvl'); + End; + End; + if ilvl < 0 or ilvl >= length(levels_) then + return ''; + str := levels_[ilvl]['text']; + for i:=ilvl downto 0 do Begin + srcFmt := '%' $ (i + 1); + destStr := _getNumStr(arr[i], levels_[i]['numFmt'], levels_[i]['start']-1); + str := ReplaceStr(str, srcFmt, destStr); + End; + return str; + End; + + Function _getNumStr(index, fmt, start); + Begin + num := index + start; + if fmt = 'decimal' or num >= 10000 then //数字项目编号 14.1.1 + return '' $ num; + //中文编号 + chNum := array('零','一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五','十六','十七','十八','十九'); + if num < 20 then + return chNum[num]; + v4 := int(num/1000); + s4 := v4 ? chNum[v4] + '千' : ''; + v3 := int((num % 1000) / 100); + s3 := v3 ? chNum[v3] + '百' : (s4 <> '' ? '零' : ''); + v2 := int((num % 100) / 10); + s2 := v2 ? chNum[v2] + '十' : ((s4+s3) <> '' ? '零' : ''); + v1 := num % 10; + s1 := v1 ? chNum[v1] : ''; + if s3='零' and s2='零' then s3 := ''; + if s1='' and s2='零' then s2 := ''; + return s4 + s3 + s2 + s1; + End; + + numFmt; + node_; + levels_; +End; + +Function _getDocObject(node, name); +Begin + p := nil; + case name of + 'w:del','w:ins': + p := new TRevision(node); + 'w:p': + p := new TParagraph(node); + 'w:tbl': + p := new TTable(node); + 'w:r': + p := new TRun(); + End; + if ifObj(p) then Begin + p.node_ := node; + p.name_ := name; + End; + return p; +End; + +///返回全部列表 +Function getDocumentObjects(parent, prefix); +Begin + ps := array(); + node := parent.FirstChildElement(); + while ifObj(node) do Begin + name := node.GetName(); + if length(prefix) = 0 or (ifstring(prefix) and name = prefix) or (istable(prefix) and (name in prefix)) then Begin + p := _getDocObject(node, name); + if p = nil then Begin + p := new DocObject(); + p.node_ := node; + p.name_ := name; + End; + ps[ length(ps) ] := p; + End; + node := node.NextElement(); + End; + return ps; +End; + +Function getDocumentObject(parent, prefix, index); +Begin + node := parent.FirstChildElement(); + cnt := 0; + while ifObj(node) do Begin + name := node.GetName(); + if length(prefix) = 0 or (ifstring(prefix) and name = prefix) or (istable(prefix) and (name in prefix)) then Begin + if cnt then Begin //第index个对象 + p := _getDocObject(node, name); + if ifObj(p) then Begin + return p; + End; + End; + cnt ++; + End; + node := node.NextElement(); + End; + return nil; +End; + +Function _text(r); +Begin + txt := ''; + for i:= 0 to length(r)-1 do Begin + if i and r[i]['pIndex'] > 0 and r[i]['pIndex'] <> r[i-1]['pIndex'] then + txt += '\n'; + if ifObj(r[i]['rNode']) then Begin + run := new TRun(r[i]['rNode']); + txt += run.Text(); + End; + End; + return txt; +End; + +Function _getHanging(linesCnt, pPr); +Begin + wth := pPr.LeftIndent + pPr.RightIndent; + if linesCnt = 0 then Begin + if pPr.Hanging then + wth -= pPr.Hanging; + else if pPr.FirstLineIndent then + wth += pPr.FirstLineIndent; + End; +//_dumpPpr(pPr); +//println('>>>>>行首,lines={}, wth={}', linesCnt, wth); + return wth; +End; + +Function _dumpPpr(pPr); +Begin + if not ifObj(pPr) then + return println('pPr is null'); + println('SpaceBefore={},SpaceAfter={},LineSpacing={},LineSpacingRule={},Left={},Right={},Hanging={},FirstLineIndent={}', + pPr.SpaceBefore, pPr.SpaceAfter, pPr.LineSpacing,pPr.LineSpacingRule,pPr.LeftIndent,pPr.RightIndent,pPr.Hanging,pPr.FirstLineIndent); +End; + +Function _dumpRpr(rPr); +Begin + if not ifObj(rPr) then + return println('rPr is null'); + println('sz={},szCs={},hint={},eastAsia={}', + rPr.Size,rPr.szCs,rPr.rFont.hint,rPr.rFont.eastAsia); +End; + +//文本前后是否包含空格 +Function _preserve(str); +Begin + if not ifstring(str) then return false; + cnt := length(str); + spaceArr := array(' ',' '); + if cnt and (str[1] in spaceArr or (cnt > 1 and str[cnt] in spaceArr)) then + return true; + return false; +End; +