日期:2014-05-18 浏览次数:20960 次
DocumentBuilder builder = new DocumentBuilder(); string imageFileName = MyDir + "Hammer.wmf"; builder.Write("Image linked, not stored in the document: "); Shape linkedOnly = new Shape(builder.Document, ShapeType.Image); linkedOnly.WrapType = WrapType.Inline; linkedOnly.ImageData.SourceFullName = imageFileName; builder.InsertNode(linkedOnly); builder.Writeln(); builder.Write("Image linked and stored in the document: "); Shape linkedAndStored = new Shape(builder.Document, ShapeType.Image); linkedAndStored.WrapType = WrapType.Inline; linkedAndStored.ImageData.SourceFullName = imageFileName; linkedAndStored.ImageData.SetImage(imageFileName); builder.InsertNode(linkedAndStored); builder.Writeln(); builder.Write("Image stored in the document, but not linked: "); Shape stored = new Shape(builder.Document, ShapeType.Image); stored.WrapType = WrapType.Inline; stored.ImageData.SetImage(imageFileName); builder.InsertNode(stored); builder.Writeln(); builder.Document.Save(MyDir + "Image.CreateLinkedImage Out.doc"); [Visual Basic] Dim builder As DocumentBuilder = New DocumentBuilder() Dim imageFileName As String = MyDir & "Hammer.wmf" builder.Write("Image linked, not stored in the document: ") Dim linkedOnly As Shape = New Shape(builder.Document, ShapeType.Image) linkedOnly.WrapType = WrapType.Inline linkedOnly.ImageData.SourceFullName = imageFileName builder.InsertNode(linkedOnly) builder.Writeln() builder.Write("Image linked and stored in the document: ") Dim linkedAndStored As Shape = New Shape(builder.Document, ShapeType.Image) linkedAndStored.WrapType = WrapType.Inline linkedAndStored.ImageData.SourceFullName = imageFileName linkedAndStored.ImageData.SetImage(imageFileName) builder.InsertNode(linkedAndStored) builder.Writeln() builder.Write("Image stored in the document, but not linked: ") Dim stored As Shape = New Shape(builder.Document, ShapeType.Image) stored.WrapType = WrapType.Inline stored.ImageData.SetImage(imageFileName) builder.InsertNode(stored) builder.Writeln() builder.Document.Save(MyDir & "Image.CreateLinkedImage Out.doc")
------解决方案--------------------
Document doc = new Document(MyDir + "Image.SampleImages.doc"); NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false); int imageIndex = 0; foreach (Shape shape in sha