下面是使用spire.doc的代码
var doc = new Document();
doc.LoadFromFile(@"E:\test.docx", FileFormat.Doc);
var image = Image.FromFile(@"E:\nice.jpg");
var picture1 = doc.Sections[0].Paragraphs[0].AppendPicture(image);
picture1.VerticalAlignment = ShapeVerticalAlignment.Top;
picture1.HorizontalAlignment = ShapeHorizontalAlignment.Left;
picture1.TextWrappingStyle = TextWrappingStyle.Square;
doc.SaveToFile(@"..\..\result.doc", FileFormat.Doc);
System.Diagnostics.Process.Start(@"..\..\result.doc");
如何使用spire.doc
或Microsoft.Office.Interop.Word
库将图像和文本插入到Word模板中的某些位置?
或者类似于将图像插入到world模板中的某个位置的link。
发布于 2018-09-10 20:51:36
使用Microsoft.Office.Interop.Word,
首先,你需要确保选择在正确的位置,
然后,插入图像,有几个选项,这是我的代码,
If bInline Then
Dim oInlineShape As InlineShape = m_oWordApp.Selection.InlineShapes.AddPicture(FileName:=sImageFilePath, LinkToFile:=False, SaveWithDocument:=True)
oInlineShape.Range.ParagraphFormat.Alignment = nAlignment
If nHeight > 0 AndAlso nWidth > 0 Then
oInlineShape.LockAspectRatio = MsoTriState.msoFalse
oInlineShape.Height = nHeight
oInlineShape.Width = nWidth
End If
Else
Dim oShape As Word.Shape = m_oWordApp.ActiveDocument.Shapes.AddPicture(Anchor:=m_oWordApp.Selection.Range, FileName:=sImageFilePath, LinkToFile:=False, SaveWithDocument:=True)
If nHeight > 0 AndAlso nWidth > 0 Then
oShape.LockAspectRatio = MsoTriState.msoFalse
oShape.Height = nHeight
oShape.Width = nWidth
End If
End If
插入文本非常简单,你只需要确保选择对象在正确的位置,然后,
m_oWordApp.Selection.Text = sMsg
'you can update background colors ....
m_oWordApp.Selection.Range.HighlightColorIndex = 0
'you update fonts ....
m_oWordApp.Selection.Font.Bold = True
希望能有所帮助。
https://stackoverflow.com/questions/19955812
复制相似问题