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();
使用response.ContentType生成WORD文档,怎么生成多页
尝试在Response.Buffer = True response.ContentType ="application/msword"Response.AddHeader "content-disposition", "attachment;filename = 工作计划表.doc"后加入Response.Flush,在页面后面加入...
sql数据输出到word
这个很简单,直接把显示到屏幕的网页输出到word文件就可以了,下面是一个ASP示例. <% .....连接数据库 Response.ContentType="application/msword"'输出到word文件 Response.AddHeader "content-disposition","attachment;filename=test.doc"'生成word的文件名 set pa=conn.execute(select * from table) do while not pa.eof response.write pa(0)&"," response.write pa(1)&"" pa.movenext loop pa.close %>
word的含义
@RequestMapping("download")public void exportWord( HttpServletRequest request, HttpServletResponse response) throws Exception {User user = AppContext.getLoginUser(); Student student = studentSvc.findByUserId(user.getId());try {//word内容String content="";byte b[] = content.getBytes("utf-8"); //这里是必须要设置编码的,不然导出中文就会乱码。
ByteArrayInputStream bais = new ByteArrayInputStream(b);//将字节数组包装到流中 /** 关键地方* 生成word格式*/POIFSFileSystem poifs = new POIFSFileSystem(); DirectoryEntry directory = poifs.getRoot(); DocumentEntry documentEntry = directory.createDocument("WordDocument", bais); //输出文件String fileName="实习考核鉴定表";request.setCharacterEncoding("utf-8"); response.setContentType("application/msword");//导出word格式response.addHeader("Content-Disposition", "attachment;filename=" +new String( (fileName + ".doc").getBytes(), "iso-8859-1"));OutputStream ostream = response.getOutputStream(); poifs.writeFilesystem(ostream); bais.close(); ostream.close(); }catch(Exception e){AppUtils.logError("导出出错:%s", e.getMessage());} }
jsp导出到word
jsp输出word在页面直接打开word。
在Action中写response.reset();response.setContentType("application/msword;charset=utf-8");response.setHeader("Content-Disposition", "inline;filename=temp.doc");response.getOutputStream().write(document.getContent()); response.getOutputStream().flush();response.getOutputStream().close();return null;在页面时下载word。
在Action中写response.reset();response.setContentType("application/x-download;charset=utf-8");response.setHeader("Content-Disposition", "attachment;filename=temp.doc");response.getOutputStream().write(document.getContent());response.getOutputStream().flush();response.getOutputStream().close();return null;
如何将excel,word等office文件转为html文本再显示带页面上
Response.ContentType = "Application/msword";//Response.ContentType = "appliation/octet-stream";Response.ClearContent();Response.ContentEncoding = System.Text.Encoding.Default;Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode((byte[])dt.Rows[0][0]));Response.BinaryWrite((byte[])dt.Rows[0][0]);
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我是否可以解决您的问题?
求教用java 生成word!!!
1-apache的POI,此方法对Excel的导出做的很好,目前对Word的导出方面的功能尚未完全。
2-纯JavaScript脚本实现。
主要通过客户端调用本机Office组件来实现。
3-在JSP页面引入头文件实现。
纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安全级别设置为中。
这样的话岂不是每台机器都要配置一下。
其次每次生成word文档以后弹出对话框(无法保存此文件,因为它已在别处打开(C:\...\STARTUP\Powerword.dot)),出现此问题就需要把C:\Documents and Settings\当前用户名\Application Data\Microsoft\Word\STARTUP下的Powerword.dot文件删除,每次遇到此问题就需要删除文件来解决,十分不方便。
JSP页面引入来实现Word保存就方便多了,但是也有不足的地方,首先如果需要引入如果需要下载的话就引入其实如果大家用框架做就方便多了,比如Struts2。
在Action里直接写如下代码:if(out!=null){String fileName="";fileName+="评价报告.doc";try {HttpServletResponse response = ServletActionContext.getResponse();response.setHeader("Content-disposition","attachment; filename="+new String(fileName.getBytes("GB2312"), "8859_1"));} catch (UnsupportedEncodingException e) {e.printStackTrace();}out是jsp页面表单元素,一个button,用于提交表单到相应Action进行Word下载。
Action设置jsp页面头文件。
这样每次点击button就可以把相应jsp页面的内容保存到Word中并且支持下载,Word中内容并且是可编辑状态。
不足的地方在于由于表内容是动态生成,有的需要先查看在下载Word,就需要另外建立一个新JSP页面进行Word下载,当然首先要在struts.xml里配置好页面转向。
新建立的页面传值同查看页面要保持一样。
转载请注明出处51数据库 » response word
王牌少妇