Type TSDocxParagraphs = Class(TSVbaBase) public Function Init(docx); Function Operator[](index); Function SerializeParagraphs(root); private docx_; lastnode_; paragraphs_; // TOfficeObj("TParagraph")数组 public Function Add(Range); Function CloseUp(); Function DecreaseSpacing(); Function IncreaseSpacing(); Function Indent(); Function IndentCharWidth(Count); Function IndentFirstLineCharWidth(Count); Function Item(Index); Function OpenOrCloseUp(); Function OpenUp(); Function Outdent(); Function OutlineDemote(); Function OutlineDemoteToBody(); Function OutlinePromote(); Function Reset(); Function Space1(); Function Space15(); Function Space2(); Function TabHangingIndent(Count); Function TabIndent(Count); property AddSpaceBetweenFarEastAndAlpha read ReadAddSpaceBetweenFarEastAndAlpha write WriteAddSpaceBetweenFarEastAndAlpha; property AddSpaceBetweenFarEastAndDigit read ReadAddSpaceBetweenFarEastAndDigit write WriteAddSpaceBetweenFarEastAndDigit; property Alignment read ReadAlignment write WriteAlignment; property AutoAdjustRightIndent read ReadAutoAdjustRightIndent write WriteAutoAdjustRightIndent; property BaseLineAlignment read ReadBaseLineAlignment write WriteBaseLineAlignment; property Borders read ReadBorders; property CharacterUnitFirstLineIndent read ReadCharacterUnitFirstLineIndent write WriteCharacterUnitFirstLineIndent; property CharacterUnitLeftIndent read ReadCharacterUnitLeftIndent write WriteCharacterUnitLeftIndent; property CharacterUnitRightIndent read ReadCharacterUnitRightIndent write WriteCharacterUnitRightIndent; property Count read ReadCount; property DisableLineHeightGrid read ReadDisableLineHeightGrid write WriteDisableLineHeightGrid; property FarEastLineBreakControl read ReadFarEastLineBreakControl write WriteFarEastLineBreakControl; property First read ReadFirst; property FirstLineIndent read ReadFirstLineIndent write WriteFirstLineIndent; property Format read ReadFormat write WriteFormat; property HalfWidthPunctuationOnTopOfLine read ReadHalfWidthPunctuationOnTopOfLine write WriteHalfWidthPunctuationOnTopOfLine; property HangingPunctuation read ReadHangingPunctuation write WriteHangingPunctuation; property Hyphenation read ReadHyphenation write WriteHyphenation; property KeepTogether read ReadKeepTogether write WriteKeepTogether; property KeepWithNext read ReadKeepWithNext write WriteKeepWithNext; property Last read ReadLast; property LeftIndent read ReadLeftIndent write WriteLeftIndent; property LineSpacing read ReadLineSpacing write WriteLineSpacing; property LineSpacingRule read ReadLineSpacingRule write WriteLineSpacingRule; property LineUnitAfter read ReadLineUnitAfter write WriteLineUnitAfter; property LineUnitBefore read ReadLineUnitBefore write WriteLineUnitBefore; property NoLineNumber read ReadNoLineNumber write WriteNoLineNumber; property OutlineLevel read ReadOutlineLevel write WriteOutlineLevel; property PageBreakBefore read ReadPageBreakBefore write WritePageBreakBefore; property ReadingOrder read ReadReadingOrder write WriteReadingOrder; property RightIndent read ReadRightIndent write WriteRightIndent; property Shading read ReadShading; property SpaceAfter read ReadSpaceAfter write WriteSpaceAfter; property SpaceAfterAuto read ReadSpaceAfterAuto write WriteSpaceAfterAuto; property SpaceBefore read ReadSpaceBefore write WriteSpaceBefore; property SpaceBeforeAuto read ReadSpaceBeforeAuto write WriteSpaceBeforeAuto; property Style read ReadStyle write WriteStyle; property TabStops read ReadTabStops write WriteTabStops; property WidowControl read ReadWidowControl write WriteWidowControl; property WordWrap read ReadWordWrap write WriteWordWrap; Function WriteWordWrap(value); Function ReadWordWrap(); Function WriteWidowControl(value); Function ReadWidowControl(); Function WriteTabStops(value); Function ReadTabStops(); Function WriteStyle(value); Function ReadStyle(); Function WriteSpaceBeforeAuto(value); Function ReadSpaceBeforeAuto(); Function WriteSpaceBefore(value); Function ReadSpaceBefore(); Function WriteSpaceAfterAuto(value); Function ReadSpaceAfterAuto(); Function WriteSpaceAfter(value); Function ReadSpaceAfter(); Function ReadShading(); Function WriteRightIndent(value); Function ReadRightIndent(); Function WriteReadingOrder(value); Function ReadReadingOrder(); Function WritePageBreakBefore(value); Function ReadPageBreakBefore(); Function WriteOutlineLevel(value); Function ReadOutlineLevel(); Function WriteNoLineNumber(value); Function ReadNoLineNumber(); Function WriteLineUnitBefore(value); Function ReadLineUnitBefore(); Function WriteLineUnitAfter(value); Function ReadLineUnitAfter(); Function WriteLineSpacingRule(value); Function ReadLineSpacingRule(); Function WriteLineSpacing(value); Function ReadLineSpacing(); Function WriteLeftIndent(value); Function ReadLeftIndent(); Function ReadLast(); Function WriteKeepWithNext(value); Function ReadKeepWithNext(); Function WriteKeepTogether(value); Function ReadKeepTogether(); Function WriteHyphenation(value); Function ReadHyphenation(); Function WriteHangingPunctuation(value); Function ReadHangingPunctuation(); Function WriteHalfWidthPunctuationOnTopOfLine(value); Function ReadHalfWidthPunctuationOnTopOfLine(); Function WriteFormat(value); Function ReadFormat(); Function WriteFirstLineIndent(value); Function ReadFirstLineIndent(); Function ReadFirst(); Function WriteFarEastLineBreakControl(value); Function ReadFarEastLineBreakControl(); Function WriteDisableLineHeightGrid(value); Function ReadDisableLineHeightGrid(); Function ReadCount(); Function WriteCharacterUnitRightIndent(value); Function ReadCharacterUnitRightIndent(); Function WriteCharacterUnitLeftIndent(value); Function ReadCharacterUnitLeftIndent(); Function WriteCharacterUnitFirstLineIndent(value); Function ReadCharacterUnitFirstLineIndent(); Function ReadBorders(); Function WriteBaseLineAlignment(value); Function ReadBaseLineAlignment(); Function WriteAutoAdjustRightIndent(value); Function ReadAutoAdjustRightIndent(); Function WriteAlignment(value); Function ReadAlignment(); Function WriteAddSpaceBetweenFarEastAndDigit(value); Function ReadAddSpaceBetweenFarEastAndDigit(); Function WriteAddSpaceBetweenFarEastAndAlpha(value); Function ReadAddSpaceBetweenFarEastAndAlpha(); End; // ============== 实现 ================= // Function TSDocxParagraphs.Init(docx); Begin docx_ := docx; paragraphs_ := array(); lastnode_ := nil; SerializeParagraphs(docx_.Body().Node()); End; Function TSDocxParagraphs.SerializeParagraphs(root); Begin node := root.FirstChildElement(); while ifObj(node) do begin name := node.GetName(); if name = "w:p" then begin obj := TOfficeObj("TParagraph"); obj.Init(node); paragraphs_[length(paragraphs_)] := obj; lastnode_ := node; end else if name = "w:tbl" then begin tr := node.FirstChildElement("w:tr"); while ifObj(tr) do begin tc := tr.FirstChildElement("w:tc"); while ifObj(tc) do begin SerializeParagraphs(tc); tc := tc.NextElement("w:tc"); end paragraphs_[length(paragraphs_)] := TOfficeObj("TParagraph"); tr := tr.NextElement("w:tr"); end lastnode_ := node; end node := node.NextElement(); End; End; Function Operator TSDocxParagraphs.[](index); Begin paragraph_obj := new TSDocxParagraph(self.Application, self.Creator, self.Parent); paragraph_obj.Init(docx_, paragraphs_[index], index + 1); return paragraph_obj; End; // Methods Function TSDocxParagraphs.Add(Range); Begin if lastnode_ then node := docx_.Body().Root().InsertAfterChild(lastnode_, "element", "w:p"); else node := docx_.Body().Root().InsertFirstChild("element", "w:p"); lastnode_ := node; obj := TOfficeObj("TParagraph"); obj.Init(node); paragraphs_[length(paragraphs_)] := obj; return self.Item(length(paragraphs_) - 1); End; Function TSDocxParagraphs.Item(Index); Begin return self[Index - 1]; End; Function TSDocxParagraphs.ReadCount(); Begin return length(paragraphs_); End; Function TSDocxParagraphs.ReadFirst(); Begin return self.Item(1); End; Function TSDocxParagraphs.ReadLast(); Begin return self.Item(self.Count); End;