c#操作word 在指定书签插入文字或者图片
2010-03-14 21:49
821 查看
using Word = Microsoft.Office.Interop.Word;
object Nothing = System.Reflection.Missing.Value;
object format = Word.WdSaveFormat.wdFormatDocument;
Word.Application wordApp = new Word.ApplicationClass();
//打开网页选择内容
object srcFileName = @"c:\new1.doc"; //里面有图片
Word.Document wordDoc2 = wordApp.Documents.Open(ref srcFileName, ref format, 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);
try
{
object bookmarkName = "jlr";
//Word.Range rng = wordDoc2.Bookmarks.get_Item(ref bookmarkName).Range;
//rng.Text = "newText";
//object range = rng;
//wordDoc2.Bookmarks.Add("jlr", ref range);
wordDoc2.Bookmarks.get_Item(ref bookmarkName).Select();
wordApp.Selection.InlineShapes.AddPicture("c:\\1.jpg", ref Nothing, ref Nothing, ref Nothing);
wordDoc2.Save();
}
catch { }
finally
{
//关闭网页wordDoc2
wordDoc2.Close(ref Nothing, ref Nothing, ref Nothing);
if (wordDoc2 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc2);
wordDoc2 = null;
}
//关闭wordApp
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
if (wordApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
wordApp = null;
}
}
GC.Collect();
object Nothing = System.Reflection.Missing.Value;
object format = Word.WdSaveFormat.wdFormatDocument;
Word.Application wordApp = new Word.ApplicationClass();
//打开网页选择内容
object srcFileName = @"c:\new1.doc"; //里面有图片
Word.Document wordDoc2 = wordApp.Documents.Open(ref srcFileName, ref format, 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);
try
{
object bookmarkName = "jlr";
//Word.Range rng = wordDoc2.Bookmarks.get_Item(ref bookmarkName).Range;
//rng.Text = "newText";
//object range = rng;
//wordDoc2.Bookmarks.Add("jlr", ref range);
wordDoc2.Bookmarks.get_Item(ref bookmarkName).Select();
wordApp.Selection.InlineShapes.AddPicture("c:\\1.jpg", ref Nothing, ref Nothing, ref Nothing);
wordDoc2.Save();
}
catch { }
finally
{
//关闭网页wordDoc2
wordDoc2.Close(ref Nothing, ref Nothing, ref Nothing);
if (wordDoc2 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc2);
wordDoc2 = null;
}
//关闭wordApp
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
if (wordApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
wordApp = null;
}
}
GC.Collect();
相关文章推荐
- c#操作word 在指定书签插入文字或者图片(转)
- c#操作word 在指定书签插入文字或者图片
- c#操作在word指定书签插入文字
- c#调用Aspose.Word组件操作word 插入文字/图片/表格 书签替换套打
- C# 操作word 指定书签位置插入图片并设置图片大小和位置
- c#调用Aspose.Word组件操作word 插入文字/图片/表格 书签替换套打
- C# 操作Word书签(二)——插入图片、表格到书签;读取、替换书签
- 用C#操作office组件库实现word文档的创建及文字 表格 图片的插入
- java2Word在Word文档指定位置插入图片或者文字
- 黄聪:C# web word文档操作,任意指定位置插入图片,表格简单操作
- java2Word在Word文档指定位置插入图片或者文字
- C#调用NPOI组件读取excel表格数据转为datatable写入word表格中并向word中插入图片/文字/书签 获得书签列表
- 黄聪:C# web word文档操作,任意指定位置插入图片,表格简单操作
- C#调用NPOI组件读取excel表格数据转为datatable写入word表格中并向word中插入图片/文字/书签 获得书签列表
- 操作Word对象----在指定位置插入图片并设置大小(原)
- C#中按模板操作Word —— 如何向Word中插入图片
- 操作Word对象----在指定位置插入图片并设置大小(原)
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- C#操作word之插入图片