将图片或者文字插入Word指定位置
来源:互联网 发布:淘宝违规商品重新上架 编辑:程序博客网 时间:2024/04/30 13:57
/// <summary>
/// 将图片插入word文档指定位置
/// </summary>
/// <param name="wordPath">word文档路径</param>
/// <param name="dicImg">Dictionary 存放word书签名称以及所对应的图片</param>
/// <param name="dicWeek">Dictionary 存放word书签名称以及所对应的文字</param>
public static void SetWord(string wordPath, Dictionary<string,string> dicImg,Dictionary<string,string> dicWeek)
{
WriteLog("进入SetWord");
WriteLog("wordPath====" + wordPath);
try
{
try
{
Process[] processes0;
processes0 = Process.GetProcessesByName("WINWORD");
foreach (Process process in processes0)
{
process.Kill();
}
}
catch(Exception err)
{
WriteLog("SetWord111===="+err.Message);
}
WriteLog("Count:" + dicImg.Count.ToString() + "," + dicWeek.Count.ToString());
object filename = wordPath;//文件名
WriteLog("aaaaaaaaaa");
Microsoft.Office.Interop.Word.Application a = new Microsoft.Office.Interop.Word.ApplicationClass();//建立一个Word程序对像
WriteLog("bbbbbbbbbb");
object Nothing = System.Reflection.Missing.Value;//空值
Microsoft.Office.Interop.Word.Document b=null;
try
{
b = a.Documents.Open(ref filename, 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);//建立一个Word文档对像
}
catch(Exception er)
{
WriteLog("er==="+er.Message);
}
WriteLog("mmmmmmmmmmmmmmmmmmmmmm");
foreach (KeyValuePair<string, string> item in dicImg)
{
object bkmC = item.Value;
if (a.ActiveDocument.Bookmarks.Exists(bkmC.ToString()) == true)
{
a.ActiveDocument.Bookmarks.get_Item(ref bkmC).Select();
}
object Anchor = a.Selection.Range;
object LinkToFile = false;
object SaveWithDocument = true;
a.ActiveDocument.InlineShapes.AddPicture(item.Key, ref LinkToFile, ref SaveWithDocument, ref Anchor);
}
foreach (KeyValuePair<string, string> item in dicWeek)
{
object bkmC = item.Key;
if (a.ActiveDocument.Bookmarks.Exists(bkmC.ToString()) == true)
{
a.ActiveDocument.Bookmarks.get_Item(ref bkmC).Range.Text = item.Value;
}
}
b.Close(ref Nothing, ref Nothing, ref Nothing);//关闭Word文档
a.Quit(ref Nothing, ref Nothing, ref Nothing);//退出Word程序
}
catch (Exception e)
{
WriteLog("setWord," + e.Message);
}
}
- 将图片或者文字插入Word指定位置
- java2Word在Word文档指定位置插入图片或者文字
- java2Word在Word文档指定位置插入图片或者文字
- c#操作word 在指定书签插入文字或者图片
- word中在指定位置插入图片
- c#操作word 在指定书签插入文字或者图片(转)
- 在word里指定书签的位置插入图片
- C# 在word文档指定位置插入图片
- word模板插入文字、图片
- C# word在指定位置插入图片,设置图片的属性
- 操作Word对象----在指定位置插入图片并设置大小(原)
- C# web word文档操作,任意指定位置插入图片,表格简单操作
- 操作Word对象----在指定位置插入图片并设置大小
- 黄聪:C# web word文档操作,任意指定位置插入图片,表格简单操作
- WPS 或者 word 插入通栏图片
- 将字符串插入到指定位置
- 将子控件插入指定位置
- word如何在图片中插入文字
- V4L基础概念
- 在Qt的Model/View框架中实现Drag-Drop操作
- DataGrid双向排序
- Windows 安装 windows Service 步骤
- HTTP协议详解(真的很经典)
- 将图片或者文字插入Word指定位置
- C# 鼠标移动到指定位置,并且单击
- HTTP协议的头信息详解
- FTP协议详解
- 由一个问题到 Resin ClassLoader 的学习
- Microsoft Web Application Stress Tool无法使用问题
- android:通过findViewById试图获取界面元素对象为Null,运行会提示空指针异常
- 查看Linux系统的非常有用的命令
- rtp协议详解/rtcp协议详解