c# 向word指定位置插入图片

shioooyin 2009-04-02 04:49:13
这是我写的代码 但是只能在第一页 插入图片
我想要的是 在任意一页任意位置都可以插入图片

Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application oWord;
Microsoft.Office.Interop.Word.Document oDoc;
object name = "d:\\wordFile/myfile.doc";
object Range = System.Reflection.Missing.Value;
oWord = new Microsoft.Office.Interop.Word.ApplicationClass();
oWord.Visible = false;
//打开文档
oDoc = oWord.Documents.Open(ref name, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
object a = true;
object b = true;
object left = null;
object top = null;
//定义位置
if (len == 1)
{
left = 80; top = 280;
}
if (len == 2)
{
left = 80; top = 480;
}
if (len == 3)
{
left = 80; top = 680;
}
if (len == 4)
{
left = 80; top = 880;
}
if (len == 5)
{
left = 80; top = 1080;
}
object width = 300;
object height = 150;
oDoc.Shapes.AddPicture(str, ref a, ref b, ref left, ref top, ref width, ref height, ref Nothing);
oDoc.Save();
oWord.Documents.Close(ref Nothing, ref Nothing, ref Nothing);


请大家 指教 谢谢!!!
...全文
440 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyliujunyou 2009-04-13
  • 打赏
  • 举报
回复
你可以用书签,也可以向某个固定的段落后面插入

不过我现在用的xml架构,这种方式可以摆脱不使用word组件,完全操作xml,速度也快!
zhouxingyu896 2009-04-06
  • 打赏
  • 举报
回复
学习

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧