110,535
社区成员
发帖
与我相关
我的任务
分享
public void InsertImage2(string imageFile)
{
object Range = System.Reflection.Missing.Value;
wdDoc.Paragraphs.Last.Range.Text = "text1";
wdDoc.Paragraphs.Add(ref Nothing);
wdDoc.Paragraphs.Last.Range.Text = "text2";
//Start Word and create a new document.
wdApp.Selection.Font.Bold = 1;
wdApp.Selection.Font.Size = 18;
wdApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
wdApp.Selection.InlineShapes.AddPicture(imageFile , ref Nothing , ref Nothing , ref Range);
}
函数:
oWord.Selection.InlineShapes.AddPicture(ref name,ref LinkToFile,ref SaveWithDocument,ref Range);
示例:
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
object name= "d:\\myfile.doc";
object Range=System.Reflection.Missing.Value;
//Start Word and create a new document.
Word.Application oWord;
Word.Document oDoc;
oWord = new Word.ApplicationClass();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,ref oMissing, ref oMissing);
oWord.Selection.Font.Bold = 1;
oWord.Selection.Font.Size=18;
oWord.Selection.ParagraphFormat.Alignment =Word.WdParagraphAlignment.wdAlignParagraphCenter;
oWord.Selection.InlineShapes.AddPicture("e:/picture/123.jpg",ref oMissing,ref oMissing,ref Range);
object Range = System.Reflection.Missing.Value;
wdDoc.Paragraphs.Last.Range.Text = "text1";
wdDoc.Paragraphs.Add(ref Nothing);
wdDoc.Paragraphs.Last.Range.Text = "text2";
//插入图片要用到Selection对象,所以应新建一个段落,然后在插入段落处调用Select()函数
wdDoc.Paragraphs.Add(ref Nothing);
wdDoc.Paragraphs.Last.Range.Select();
//Start Word and create a new document.
wdApp.Selection.Font.Bold = 1;
wdApp.Selection.Font.Size = 18;
wdApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
wdApp.Selection.InlineShapes.AddPicture(imageFile , ref Nothing , ref Nothing , ref Range);