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文档内容显示
操作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
如何把书上的文字转换为word文档
把书上的字快速弄到电脑windows系统上, 在工作中,我常常在想,要是能把纸上有用的文字快速输入到电脑中,不用打字录入便可以大大提高工作效率该有多好呀!随着科技的发展, 这个问题在不断的解决,例如,ghost xp现在市场上的扫描仪就带有OCR软件,可以把扫描的文字转换到电脑xp系统中进行编辑。
但是,对于我们平常人来说,大多数人都是即不想多花钱购买不常用的设备,又不想费力气打字录入,那系统之家就给大家提供一个我刚刚发现的方法吧!现在数码相机很普遍,也很常用,我们就从这里下手吧。
工具/原料硬件: 电脑一台(win7系统或xp)、 数码相机软件: word2003(其它的版本我没有实验)doPDF (可以搜索下载,是一款免费的PDF制作软件)AJViewer软件(可以搜索下载,是一款免费的阅读器)步骤1步骤:1、在电脑xp系统下载中安装 doPDF和AJViewer2、用数码相机把需要的文字拍下来(相机和照像水平就不多谈了。
照片效果越好,可以大大缩小转换文字的误差率)3、在Ghost xp sp3的word中插入你用数码相机照的书上的文字(打开word——插入菜单——图片——来自文件——选择照片——插入)4、在word中选择文件菜单——打印——在打印机选项中选择doPDF——确定——点击“浏览”选项——选择文件保存的位置和填写文件名称——保存——确定5、按照上面的步骤,最新xp系统下载电脑会自动打开AJViewer软件,若没有自动打开该软件,可以自己打开AJViewer软件,然后在AJViewer中打开刚刚转换的PDF文件。
6、选择AJViewer中的,然后在需要的文字部分拖动鼠标画出虚线。
7、点击xp操作系统上发送到word按钮,就可以转换成word文件了。
可以编辑. 第6、7步骤图片如下:END注意事项1、照片一定要平整,最好对比强烈。
(e131[/em]最最关键的部分)2、用doPDF生成PDF文件不只一种用法,你也可以选择其它更好、更便捷的方法,这里只提供我本此的实验软件。
3、如果熟练的使用我的方法,系统下载用不了一分钟就可以转出若干的文字,大大提高了工作效率4、切记:输出的文字一定要校对呀!
asp.net导出word
public void Download(){Random rd = new Random();string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";//存储路径string path = Server.MapPath(fileName);//创建字符输出流StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);//需要导出的内容string str = "无标题文档这里放从数据库导出的word文档内容";//写入sw.Write(str);sw.Close();Response.Clear();Response.Buffer = true;this.EnableViewState = false;Response.Charset = "utf-8";Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));Response.ContentType = "application/octet-stream";Response.WriteFile(path);Response.Flush();Response.Close();Response.End();}标准word文档的格式微软暂未公布,由此我们可将需要导出的内容转为标准HTML文件储存,后缀名为.doc也可以将要导出内容转为标准XML格式存储,改后缀为.doc具体格式随意新建个word文档,输入内容,另存为.XML可见另外一种导出方式为word导出标准格式,服务器需要安装Microsoft Office word,需要预先设置好一个word文档并在要插入内容的地方设置书签做为模版,导出word文档时需要先遍历模版文件中的所有书签,然后给书签赋值就能实现导出数据了还有不懂的可以直接百度HI我是否可以解决您的问题?
asp.net 如何调用客户端word程序打开服务器上的word文档进行查看
工具:捷速OCR文字识别软件。
1、首先需要将纸质旧文档用扫描仪扫描下来。
为了防止数据丢失可以先保存在电脑或者U盘等设备中。
2、然后,需要在电脑上安装软件运行就可以了。
3、双击打开已经下载好的软件,可以看到弹出的对话框,选择“从图片读文件”。
(如果没有保存在电脑中也可以选择“从扫描器读文件”)接着会弹出“打开”对话框,选择保存扫描文件的文件夹,打开需要编辑的扫描文件。
4、文件添加成功,直接用鼠标选中需要识别的文字直接点击“识别”按钮。
红色的文字是可能识别错误的文字需要手工更改。
5、最后得到的识别结果根据自身的要求选择保存格式,这里需要保存为word就直接点击Word就可以了。
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文档页数
通过SOAOffice客户端控件上传word文档,在页面里添加隐藏域在页面的js保存按钮事件里添脚本document.getElementById("pgCount").value = SOAOfficeCtrl.Document.BuiltInDocumentProperties(14).Value;在保存页面SaveDoc.aspx里调用iPageCount = int32.Parse(SaveObj.RequestFormField("pgCount"));iPageCount就是你要的上传的文档的页数
转载请注明出处51数据库 » 在asp.net中怎么给word文档的书
污力胸毛