Type TSDocxInlineShapes = Class(TSVbaBase) public Function Init(docx); Function Operator[](index); Function SerializeInlineShapes(); Function FindInlineShapePosition(node); private docx_; inline_shapes_; document_; public // Methods Function AddChart2(Style, Type, Range, NewLayout); Function AddHorizontalLine(FileName, Range); Function AddHorizontalLineStandard(Range); Function AddOLEControl(ClassType, Range); Function AddOLEObject(ClassType, FileName, LinkToFile, DisplayAsIcon, IconFileName, IconIndex, IconLabel, Range); Function AddPicture(FileName, LinkToFile, SaveWithDocument, Range); Function AddPictureBullet(FileName, Range); Function AddSmartArt(Layout, Range); Function AddWebVideo(EmbedCode, VideoWidth, VideoHeight, PosterFrameImage, Url, Range); Function Item(Index); Function New(Range); // Properties property Count read ReadCount; Function ReadCount(); End; // ============== 实现 ================= // Function TSDocxInlineShapes.Init(docx); Begin docx_ := docx; inline_shapes_ := array(); document_ := self.Parent; self.SerializeInlineShapes(); End; Function Operator TSDocxInlineShapes.[](index); Begin inline_shape_obj := new TSDocxInlineShape(self.Application, self.Creator, self.Parent); inline_shape_obj.Init(docx_, inline_shapes_[index - 1]); return inline_shape_obj; End; Function TSDocxInlineShapes.SerializeInlineShapes(); Begin paragraphs := document_.Paragraphs; num := paragraphs.Count; for i:=1 to num do begin paragraph := paragraphs.Item(i); node := paragraph.Object().Root(); if ifObj(node) then begin run := node.FirstChildElement("w:r"); while ifObj(run) do begin drawing := run.FirstChildElement("w:drawing"); if ifObj(drawing) then begin trun := TOfficeObj("TRun"); trun.Init(run); inline_shapes_[length(inline_shapes_)] := trun; end run := run.NextElement("w:r"); end end end End; // Methods Function TSDocxInlineShapes.AddPicture(FileName, LinkToFile, SaveWithDocument, Range); Begin if not ifBinary(FileName) then raise "TSVBA::Parameter LinkToFile must be in binary."; picture := TOfficeObj("TPicture"); picture.Image := FileName; if ifObj(Range) then begin paragraph := Range.InsertNewParagraph(); pic := docx_.AddPicture(picture, paragraph.Object()); document_.Paragraphs.AddParagraph(paragraph.Index(), pic.Root()); paragraph.Range.Delete(); self.SerializeInlineShapes(); run := pic.Root().FirstChildElement("w:r"); trun := TOfficeObj("TRun"); trun.Init(run); end else begin last := document_.Paragraphs.Item(document_.Paragraphs.Count); pic := docx_.AddPicture(picture, last.Object()); document_.Paragraphs.AddParagraph(nil, pic.Root()); run := pic.Root().FirstChildElement("w:r"); trun := TOfficeObj("TRun"); trun.Init(run); inline_shapes_[length(inline_shapes_)] := trun; end inline_shape_obj := new TSDocxInlineShape(self.Application, self.Creator, self.Parent); inline_shape_obj.Init(docx_, trun); return inline_shape_obj; End; Function TSDocxInlineShapes.Item(Index); Begin return self[Index]; End; // Properties Function TSDocxInlineShapes.ReadCount(); Begin return length(inline_shapes_); End;