猿问

关于导出word的问题

我是用的代码是:

 

 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>"这样的东西。这个问题怎么解决啊!

回首忆惘然
浏览 295回答 1
1回答

慕哥9229398

你这个如果只是把模版文件填值,出现word标签的话就很奇怪了. 不过你先试试看.File.Copy(TemplateFile, FileName);这个是没必要的.你可以直接打开这个文件TemplateFile 然后保存为FileName就好,没必要先Copy.
随时随地看视频慕课网APP
我要回答