asp.net读取word文档 asp读取word文档 - 电脑|办公 - 电脑办公-杀毒安全-网络-V3学习网
微商网
 
 
导航:首页 |电脑|办公|正文

asp.net读取word文档 asp读取word文档

时间:2020-06-29 09:41:32
asp net页面读取word文档内容显示 操作WORD配置说明 引入:Word的对象库文件“MSWORD OLB”(word 2000为MSWORD9 OLB)1 运行Dcomcnfg exe 2
作者:

asp.net读取word文档

asp.net页面读取word文档内容显示

操作WORD配置说明 引入:Word的对象库文件“MSWORD.OLB”(word 2000为MSWORD9.OLB)1.运行Dcomcnfg.exe 2.组件服务――计算机――我的电脑――DCOM配置――找到microsoft word 文档 3.点击属性 4.选择“安全性” 5.选定“使用自定义访问权限”和“使用自定义启动权限” 6.分别编辑权限,添加Everyone(ASPNET,VS Developers,Debugger User)7.选择“身份标识”,在选定“交互式用户” 即可 8.在Web.config里加 identity impersonate="true"/ C#:ASP.NET操作Word文档一直是一个大家比较关心的话题,其实在ASP.NET里操作Word文档一点也不难,大家只需按本文提示,就能轻轻松松操作Word文档!一、准备工作 首先请确认服务端已经安装了Office Word(以下将以Office XP为例),操作系统为win2000或XP,并且已配置好.NET的运行环境及安装VS.NET C#开发环境后,我们就可以打开VS.NET,并新建一个Visual C#项目ASP.NET Web应用程序,位置为“”。

(如图一) 二、引用Word对象库文件 要操作Word,我们就需要Word的对象库文件“MSWORD.OLB”(word 2000为MSWORD9.OLB),通常安装了Office Word后,你就可以在office安装目录的Office10文件夹下面找到这个文件,当我们将这个文件引入到项目后,我们就可以在源码中使用各种操作函数来操作Word。

具体做法是打开菜单栏中的项目添加引用浏览,在打开的“选择组件”对话框中找到MSWORD.OLB后按确定即可引入此对象库文件,vs.net将会自动将库文件转化为DLL组件,这样我们只要在源码中创建该组件对象即可达到操作Word的目的! 答案补充 三、Webform1.aspx.cs代码 完成添加引用后,MSWORD.OLB已经转化为相关DLL文件并放置于项目的BIN目录下了,这样我们只需在源码中创建该对象,并使用word库文件内置的操作函数即可轻松实现操作Word,Webform1.aspx.cs源码请参见 五、web.config设置 web.config文件还需添加一句 identity impersonate="true"/以启用模拟身份,因为默认ASPNET这个用户是没有权限访问Word.ApplicationClass(),当启用模拟身份后所有页面将会使用匿名Internet用户帐户(IUSR_machinename)这个用户名的权限执行,这样我们就能成功访问Word.ApplicationClass()并在ASP.NET中操作Word!//传文档所在路径 返回文档内容 public string Doc2Text(string docFileName) { //实例化COM Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); object fileobj = docFileName; object nullobj = System.Reflection.Missing.Value; //打开指定文件(不同版本的COM参数个数有差异,一般而言除第一个外都用nullobj就行了) Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref fileobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj ); //取得doc文件中的文本 string outText = doc.Content.Text; //关闭文件 doc.Close(ref nullobj, ref nullobj, ref nullobj); //关闭COM wordApp.Quit(ref nullobj, ref nullobj, ref nullobj); //返回 return outText; } 当然 在读取的时候会有损坏的文件 和被加密的文件等问题 总之C#和office的兼容性不太好 别忘了要引用word的dll 引用文件夹 右键添加引用 在组件里找Microsoft.Office.Interop.Word

asp.net 在页面上显示本地的word文档里的内容。

网上方法不少,可以尝试搜索一下。

第一种方法:Response.ClearContent();Response.ClearHeaders();Response.ContentType = "Application/msword";string s=Server.MapPath("E:/wendang/wo582.doc");Response.WriteFile("E:/wendang/wo582.doc");Response.Write(s);Response.Flush();Response.Close();第二种方法:Response.ClearContent();Response.ClearHeaders();Response.ContentType = "Application/msword"; string strFilePath=""; strFilePath =Server.MapPath("E:/wendang/wo582.doc"); FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);Response.WriteFile(strFilePath,0,fs.Length);fs.Close(); 第三种方法:string path=Server.MapPath("E:/wendang/wo582.doc");FileInfo file=new FileInfo(path);FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);byte[] filedata=new Byte[file.Length];myfileStream.Read(filedata,0,(int)(file.Length));myfileStream.Close();Response.Clear();Response.ContentType="application/msword";Response.AddHeader("Content-Disposition","attachment;filename=wo582.doc");Response.Flush();Response.BinaryWrite(filedata);Response.End();

asp.net如何下载已经上传到数据库中的Word文档(C#)

C#编程,将Word转PDF,该方法有一定弊端,但是比起网路上的其他方法来说,还算比较好的,弊端是需要客户机上安装有WORD 2007或更高的版本。

1、添加引用: Microsoft.Office.Interop.Word版本12.0.0.0; 2、在开头添加命名空间引用:using Microsoft.Office.Interop.Word; 3、具体实现方法如下: //Word转换成pdf /// /// 把Word文件转换成为PDF格式文件 /// ///源文件路径 ///目标文件路径 ///true=转换成功 privatebool WordToPDF(string sourcePath, string targetPath) { bool result = false; Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF; object paramMissing = Type.Missing; Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document wordDocument = null; try { object paramSourceDocPath = sourcePath; string paramExportFilePath = targetPath; Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat; bool paramOpenAfterExport = false; Microsoft.Office.Interop.Word.WdExportOptimizeFor paramExportOptimizeFor = Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Microsoft.Office.Interop.Word.WdExportRange paramExportRange = Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; Microsoft.Office.Interop.Word.WdExportItem paramExportItem = Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; Microsoft.Office.Interop.Word.WdExportCreateBookmarks paramCreateBookmarks = Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; wordDocument = wordApplication.Documents.Open( ref paramSourceDocPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing); if (wordDocument != null) wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing); result = true; if (wordDocument != null) { wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; } if (wordApplication != null) { wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } catch { result = false; if (wordDocument != null) { wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; } if (wordApplication != null) {

我想在asp.net中,像百度文库那样,显示word,pdf文档,请问谁有完...

读取word的代码如下; Word.ApplicationClass wordApp=new ApplicationClass(); object file=path;(//译注:这个path是函数的参数,表示Word的路径) object nullobj=System.Reflection.Missing.Value; Word.Document doc = wordApp.Documents.Open( ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); IDataObject data=Clipboard.GetDataObject(); string mytext==data.GetData(DataFormats.Text).ToString(); doc.Close(); string[] temp= mytext.Split(" "); foreach(string i in temp) { MessageBox.Show(i); } 追问 你好,老是报这个错哦。

错误 1 “Open”方法没有采用“12”个参数的重载 F:\我的文档\Visual Studio 2005\Projects\排考\Form1.cs 241 33 WindowsApplication4 不知道该怎么办 回答 使用word对象需要先在项目引用中添加COM组件中 Microsoft Word 12.0 object library,然后using Word = Microsoft.Office.Interop.Word; 然后在你的事件里添加如下代码:Word.ApplicationClass wordApp = new Word.ApplicationClass(); object file=@"C:\Documents and Settings\wangchuan\桌面\关键词.doc"; object nullobj=System.Reflection.Missing.Value; Word.Document doc = wordApp.Documents.Open( ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,ref nullobj); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); IDataObject data=Clipboard.GetDataObject(); string mytext=data.GetData(DataFormats.Text).ToString(); doc.Close(ref nullobj, ref nullobj, ref nullobj); string[] temp= mytext.Split(" "); foreach(string i in temp) { MessageBox.Show(i); } pdf我不知道。

应该可以用插件读。

显示的时候,很容易了。

flash本身支持读取xml。

让flash读c#生成的xml就可以了

ASP.NET中怎样将一个文本文件的内容读取到ASPX页面上?

JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法 OFFICE文档使用POI控件,PDF可以使用PDFBOX0.7.3控件,完全支持中文,用XPDF也行,不过感觉PDFBOX比较好,而且作者也在更新。

水平有限,万望各位指正 WORD: import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.poi.hwpf.extractor.WordExtractor; import java.io.File; import java.io.InputStream; import java.io.FileInputStream; import com.search.code.Index; public Document getDocument(Index index, String url, String title, InputStream is) throws DocCenterException { String bodyText = null; try { WordExtractor ex = new WordExtractor(is);//is是WORD文件的InputStream bodyText = ex.getText(); if(!bodyText.equals("")){ index.AddIndex(url, title, bodyText); } }catch (DocCenterException e) { throw new DocCenterException("无法从该Mocriosoft Word文档中提取内容", e); }catch(Exception e){ e.printStackTrace(); } } return null; } Excel: import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; import java.io.File; import java.io.InputStream; import java.io.FileInputStream; import com.search.code.Index; public Document getDocument(Index index, String url, String title, InputStream is) throws DocCenterException { StringBuffer content = new StringBuffer(); try{

asp.net获取某一个文件夹下所有的子文件夹

string[] files = System.IO.Directory.GetFiles(@"D:\OD\", "*.doc",System.IO.SearchOption.TopDirectoryOnly);//获取该目录下的Doc文件string[] files = System.IO.Directory.GetFiles(@"D:\OD\", "*.docx",System.IO.SearchOption.TopDirectoryOnly);//获取该目录下的Docx文件string[] files = System.IO.Directory.GetDirectories(@"D:\OD\");//获取子文件夹 首先根据你的类型可以进行分组,如文件夹,和Word文档,也可以不分组.最后从上面的代码中获取到文件夹和Word名称,做为项加入到组中,然后再根据项选选择相应的图片就可以了(如Word样式的图片或是文件夹样式的图片)...

大家还关注
    
阅读排行
推荐阅读