C#.net word 受控编程系列1-向word中插入图片

 

expression.AddPicture(FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height, Anchor)
Anchor=weboledocument.Selection.Range
可以将你的图片插入到你光标所在的位置

    Word.Document wd = objWinWordControl.document;
                Word.Application wa 
= wd.Application;
                
string fileName="D:\\File0001.jpg";
                
object LinkToFile=false;
                
object SaveWithDocument=true;
                
object Range=Missing.Value;
//                object first=wd.Characters.Count-2;
//                object last=wd.Characters.Count;
                object Left=1;
                
object Top=1;
                
object Width=100;
                
object Height=100;
                
object Anchor=wd.Application.Selection.Range;
                                
                wd.Application.ActiveDocument.Shapes.AddPicture(fileName,
ref LinkToFile,ref SaveWithDocument,ref Left,ref Top,ref Width,ref Height,ref Anchor);
                

下一步就是设置图片的属性了,参考了kingchang2000(镖骑大将)的js文章
=============code==================
/*
------------------------------------------------
描述:将图片插入在文档的末尾
设置图片的位置以及浮动于文字下的版式
参数:myDocApp -- word.application对象
myDoc -- 指定文件对象,
就是myDocApp.ActiveDocument
FilePath -- 文件路径
------------------------------------------------
*/

function InsertSignet(myDocApp,myDoc,FilePath){
try{
var mySel = myDocApp.Selection; 
mySel.EndKey(
6); //类似于ctrl+end功能,到文档的末尾。
var anchor = mySel.Range; //获取所在光标的range对象
//
添加本地图片
var pic = myDoc.Shapes.AddPicture(FilePath,false,true,300,500,100,100,anchor);
//获取wrapformat对象
var picArround = pic.WrapFormat;
//图片成水印状态,设置图片的位置以及浮动于文字下的版式
picArround.Type = 5;
pic.select(); 
//选择图片
}
catch(e){alert("Error:"+e.Description);}
}
posted @ 2006-05-24 22:41  BigKiteasdasd  阅读(4426)  评论(2编辑  收藏  举报