我是用的代码是:
Word.Application app = new Word.Application();
//模板文件
string TemplateFile = "";//@"E:\work\testPrint.doc";
...............
//模板文件拷贝到新文件
File.Copy(TemplateFile, FileName);
Word.Document doc = new Word.Document();
object Obj_FileName = FileName;
object Visible = false;
object;
object missing = System.Reflection.Missing.Value;
//打开文件
doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
doc.Activate();
foreach (Word.Bookmark bm in doc.Bookmarks)
{
if (bm.Name == "title")
{
bm.Select();
bm.Range.Text = title;
}
else if (bm.Name == "content")
{
bm.Select();
//bm.Range.Text = Comm.StripHTML(content);
bm.Range.Text = content;
}
}
我的问题是: 导出的内容中有很多word标签。像"<span>","<P>","<?xml:namespace>"这样的东西。这个问题怎么解决啊!
你这个如果只是把模版文件填值,出现word标签的话就很奇怪了.
不过你先试试看.File.Copy(TemplateFile, FileName);这个是没必要的.你可以直接打开这个文件TemplateFile
然后保存为FileName就好,没必要先Copy.