C# word表格中插入图片问题

认真学编程 2010-09-15 09:48:17
我点击Button1按钮,把文本框内容和image控件中的图片读入到在已做好的word表格的相应的单元格中,当第二次点击按钮读入时文本框内容可以覆盖掉原来word中的内容,但图片无法覆盖,即两张图片同时存在于word表格中,请问只显示第二次的图片要怎么实现啊,我的代码如下:
//插入图片
newTable.Cell(2, 1).Select();//图片插入第二行第一列
string lj = "D:\\" + this.Image1.ImageUrl;
object LinkToFile = false ;
object SaveWithDocument = true;
object Anchor = WordDoc.Application.Selection.Range;
WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(lj , ref LinkToFile, ref SaveWithDocument, ref Anchor);
//保存文件
WordDoc.SaveAs(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
WordApp.NormalTemplate.Saved = true;
WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
...全文
1303 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
认真学编程 2010-10-15
  • 打赏
  • 举报
回复
newTable.Cell(2, 1).Range.Text = "";
newTable.Cell(2, 1).Select();//图片插入第二行第一列
hujinm123 2010-10-13
  • 打赏
  • 举报
回复
newTable.Cell(2, 1).Range.Text = "";
hujinm123 2010-10-13
  • 打赏
  • 举报
回复
先把当前单元格清空了,再插入文字图片
bloodish 2010-10-13
  • 打赏
  • 举报
回复
试试这样删
Word.Shape deleteSharp = null;
foreach (Word.Shape s in doc.InlineShapes)
{
if(s.Anchor == newTable.Cell(2,1).Range)
{
deleteSharp = s;
break;
}
}
if(deleteSharp != null)
{
deleteSharp.Delete();
}
认真学编程 2010-10-13
  • 打赏
  • 举报
回复
试了还是不行,不太明白是在第一行第一列插入文本框文字就能自动替换,图片就不行,望指点
  • 打赏
  • 举报
回复
newTable.Cell(2, 1).Range.Text = "";不行,那百度下吧!呵呵,帮顶!
认真学编程 2010-10-13
  • 打赏
  • 举报
回复
还是不行,继续请教
bloodish 2010-10-12
  • 打赏
  • 举报
回复
先删再加

newTable.Cell(2, 1).Range.Select();
WordDoc.Application.Selection.TypeBackspace();
认真学编程 2010-10-12
  • 打赏
  • 举报
回复
问题没解决,请教请教
秋的红果实 2010-09-17
  • 打赏
  • 举报
回复
你不能先把原来的图片删除?

我很久前写过这种程序,记不清了。还有就是,将图片存储到本机上,再操作
认真学编程 2010-09-17
  • 打赏
  • 举报
回复
自己再顶!
xhueducls 2010-09-15
  • 打赏
  • 举报
回复
没用过,帮顶
认真学编程 2010-09-15
  • 打赏
  • 举报
回复
自己顶!请教啦!

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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