C# 如何将图像和文本插入Microsoft Word模板?
下面是带spire.doc的代码C# 如何将图像和文本插入Microsoft Word模板?,c#,spire.doc,C#,Spire.doc,下面是带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 = ShapeVerticalAli
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模板中的特定位置
或者类似于将图像插入到世界模板中的特定位置。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
希望能有帮助