日期:2014-05-17  浏览次数:20353 次

求解决方法,生成一份word需要30秒,太慢了要提速,同样的我用NPOI控件生成Excel表10份简历才需要1-2秒

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using Microsoft.Office.Interop.Word;
using System.Net;
using System.Web;
using System.Data;
using System.Text.RegularExpressions;

namespace OfficeOperate
{
    public class WordOperate
    {
        bool leicai = true;

        #region 新建Word文档
        /// <summary>
        /// 动态生成Word文档并填充内容 
        /// </summary>
        /// <param name="dir">文档目录</param>
        /// <param name="fileName">文档名</param>
        /// <returns>返回自定义信息</returns>
        public static bool CreateWordFile(string dir, string fileName)
        {
            Object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
            Object oMissing = System.Reflection.Missing.Value;

            if (!Directory.Exists(dir))
            {
                //创建文件所在目录
                Directory.CreateDirectory(dir);
            }
            //创建Word文档(Microsoft.Office.Interop.Word)
            Microsoft.Office.Interop.Word._Application WordApp = new Application();
            WordApp.Visible = true;
            Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Add(
                ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //保存
            object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;//
            object filename = dir + fileName;
            WordDoc.SaveAs(ref filename, ref FileFormat, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,