您的位置:首页 > 编程语言 > C#

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

2006-05-24 22:41 393 查看

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==================
/**//*
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);}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: