asp.net 替换word内容 ,里边含图片 替换后样式 和图片不能丢失Microsoft.Office.Interop.Word.Application app =new Microsoft.Office.Interop.Word.Application();
object nullobj = System.Reflection.Missing.Value;
object file = filePath;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.Content.Text = doc.Content.Text.Replace(strOld, strNew);
doc.Close(ref nullobj, ref nullobj, ref nullobj);
//关闭应用
app.Quit(ref nullobj, ref nullobj, ref nullobj);
app=null;
GC.Collect();
我用的这个方法,但是替换后样式变了,图片也没了,
请教高手有没有其他方法
object nullobj = System.Reflection.Missing.Value;
object file = filePath;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.Content.Text = doc.Content.Text.Replace(strOld, strNew);
doc.Close(ref nullobj, ref nullobj, ref nullobj);
//关闭应用
app.Quit(ref nullobj, ref nullobj, ref nullobj);
app=null;
GC.Collect();
我用的这个方法,但是替换后样式变了,图片也没了,
请教高手有没有其他方法
解决方案 »
- iframe框架右边显示不完整怎么解决?
- byte[]转string 乱码!!!!!!!!!!!!!!
- 使两种不同类型的数据结合成一个类型的方法
- 数据库被封住成dll文件有没办法查看呢
- 如何给动态生成的模板列dropdownlist添加事件?
- GridView如何在进入编辑时对DropDownList进行绑定
- textbox上传包含html标记格式的文件遇到安全问题,怎么解决啊,是不是asp.net的安全措施啊,帮帮忙解决啊!!
- 一个关于ASP.NET2005页面布局问题大家帮着解答一下。
- datagrid更新是验证的的问题!
- 如果把XML中的数据读到DROPDOWNLIST控件?
- 如果我前台的一个表格 我想增加弹出小窗口的功能 怎么弄
- 处理数据时如果网络连接突然中断,程序 ……
object MissingValue = Type.Missing;
object file = Server.MapPath("Word表头.doc");
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(
ref file, ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue, ref MissingValue, ref MissingValue);
//doc.Content.Find.Text = strOldText ;
object FindText, ReplaceWith, Replace ;//
string strold="$表头标题;$标题头;$工程名称;$报价单号;$报价日期;$合计";
string[] str_old=strold.Split(';');
string strnew="表头标题00;标题头01;工程名称02;报价单号03;报价日期04;合计05";
string[] str_new=strnew.Split(';');
for(int i=0;i<str_old.Length;i++)
{
doc.Content.Find.Text =str_old[i];// strOldText ;
FindText =str_old[i];// strOldText ;//要查找的文本
ReplaceWith =str_new[i];// strNewText ;//替换文本
Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll ;/**//*wdReplaceAll - 替换找到的所有项。
* wdReplaceNone - 不替换找到的任何项。
* wdReplaceOne - 替换找到的第一项。
* */
doc.Content.Find.ClearFormatting();//移除Find的搜索文本和段落格式设置
if (doc.Content.Find.Execute(
ref FindText,ref MissingValue,
ref MissingValue,ref MissingValue,
ref MissingValue,ref MissingValue,
ref MissingValue,ref MissingValue,ref MissingValue,
ref ReplaceWith,ref Replace,
ref MissingValue,ref MissingValue,
ref MissingValue,ref MissingValue))
{
}
}
doc.Save();
doc.Close(ref MissingValue, ref MissingValue, ref MissingValue);
//关闭应用
app.Quit(ref MissingValue, ref MissingValue, ref MissingValue);
app=null;
GC.Collect(); 问题解决了,上边的方法。