介绍做素食的网站,平台免费推广,网站建设阐述,免费网站建设必择山东绘政科技在网络上看到很多关于ASP.NET导出DOC文档的例子#xff0c;有的干脆就直接将html页面不做任何处理直接导出为DOC文件#xff0c;但是那样会有很多错误#xff0c;例如将某些控件显示为图片。我还曾经见过微软为中国某个大公司制作的一个XX系统#xff0c;导出的DOC文件实际…在网络上看到很多关于ASP.NET导出DOC文档的例子有的干脆就直接将html页面不做任何处理直接导出为DOC文件但是那样会有很多错误例如将某些控件显示为图片。我还曾经见过微软为中国某个大公司制作的一个XX系统导出的DOC文件实际上是某种特殊格式的XML但是对于这个技术我还不是很了解。于是我在网络上收集资料找到很多种实现方法一一实验最后总结出以下经验。一、首先配置系统环境1、在命令行work 的sdk命令行提示中输入dcomcnfg会显示出“组件服务”管理器2、打开“组件服务》计算机》我的电脑》DCOM 配置”找到“Microsoft Word文档”单击右键选择“属性”3、在“属性”对话框中单击“安全”选项卡在“启动和激活权限”处选择“自定义”再单击右边的”编辑“在弹出的对话框中添加”ASPNET“在IIS6中是NETWORD SERVICE用户给予”本地启动“和”本地激活“的权限单击”确定“关闭”组件服务“管理器。这样就能在Asp.net页面中访问Word对象了。 二、修改WEB.CONFIG在system.web区段内加入identity impersonatetrue/三、添加引用《网站》——《添加引用》——《COM》——Microsoft Word 11.0 Object Library四、添加命名空间引用using Microsoft.Office.Interop.Word;五代码Object Nothing System.Reflection.Missing.Value;//取得Word文件保存路径 object filename c:\aa.doc;//创建一个名为WordApp的组件对象 Microsoft.Office.Interop.Word.Application WordApp new ApplicationClass(); //网络上有写代码中直接使用Word.Application WordApp new ApplicationClass(); 但我在实际编写中总是出现错误。//创建一个名为WordDoc的文档对象 Microsoft.Office.Interop.Word.Document WordDoc WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);//增加一表格 Microsoft.Office.Interop.Word.Table table WordDoc.Tables.Add(WordApp.Selection.Range, 3, 3, ref Nothing, ref Nothing);//在表格第一单元格中添加自定义的文字内容 table.Cell(1, 1).Range.Text lllll;//在文档空白地方添加文字内容 WordDoc.Paragraphs.Last.Range.Text Wellcome To Aspxcn.Com;//将WordDoc文档对象的内容保存为DOC文档 WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);//关闭WordDoc文档对象 WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);//关闭WordApp组件对象 WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);转载于:https://www.cnblogs.com/hyl8218/archive/2010/08/23/1806129.html