日期:2014-05-16  浏览次数:20447 次

asp.net导出网页数据至Word文档出现的问题
      我想把网页的一些数据导出至Word文档,在网上找了一段代码(原代码帖子后面附上)进行测试,运行那段代码时,显示错误信息为:“检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问。 (异常来自 HRESULT:0x80070005 (E_ACCESSDENIED))。 ”
请问这个可以怎样处理?

        public string CreateWordFile(string CheckedInfo)
        {
            string message = "";
            try
            {
                Object Nothing = System.Reflection.Missing.Value;
                Directory.CreateDirectory("C:\\CNSI"); //创建文件所在目录
                string name = "CNSI.doc";
                object filename = "C:\\CNSI\\" + name; //文件保存路径
                //创建Word文档
                Word.Application WordApp = new Word.ApplicationClass();                
                Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

                //添加页眉
                WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
                WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
                WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]");
                WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
                WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置

                WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距

                /*WordDoc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape; //设置页面为纵向
                            WordDoc.PageSetup.PageHeight = WordApp.CentimetersToPoints(21F);
                            WordDoc.PageSetup.PageWidth =