response导出word response word - 电脑|办公 - 电脑办公-杀毒安全-网络-V3学习网
微商网
 
 
导航:首页 |电脑|办公|正文

response导出word response word

时间:2021-02-26 11:49:26
jsp导出到wordjsp输出word在页面直接打开word。在Action中写response reset();response setContentType("application msword
作者:

response导出word

jsp导出到word

jsp输出word在页面直接打开word。

在Action中写response.reset();response.setContentType("application/msword;charset=GBK");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=GBK");response.setHeader("Content-Disposition", "attachment;filename=temp.doc");response.getOutputStream().write(document.getContent());response.getOutputStream().flush();response.getOutputStream().close();return null;

java怎么由html生成word,保留html样式

@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文件需要利用apache的POI来完成。

核心代码如下:其实如果用框架做就方便多了,比如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中内容并且是可编辑状态。

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 %>

我要用C#,NET 导出一个word文档。

文档内容只要一个表格。

楼上的 你能不能改写下这个例子啊? 我这个只能导出字符 不能导出表格 string title = "个人信息"; object titleLengh = title.Length; string first = "\n 公司最近需要利用C#对项目进行编程,其" + "中存在一个功能就是可自动生成WORD文档,但一直以来都" + "找不到什么好办法,无奈之下,只有自已学着写一个了."; object firstLengh = first.Length; string second = "\n 如果能真正生成WORD文档的好处有:"; object secondLengh = second.Length; string third = "\n1、根据数据库信息自动生成文档;"; object thirdLengh = third.Length; string forth = "\n2、免去书写文档之苦;"; object forthLengh = forth.Length; string fifth = "\n3、可以通过邮件方式传出文档。

"; object fifthLengh = fifth.Length; object missing; object zero = 0; object c = 10; object one = 1; object two = 2; object tree = 3; object four = 4; object five = 5; object six = 6; object seven = 7; object eight = 8; object nine = 9; object ten = 10; Object Nothing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.ApplicationClass wa = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document WordDoc = wa.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); missing = System.Reflection.Missing.Value; wa.Visible = true; wa.Documents.Add(ref missing, ref missing, ref missing, ref missing); Microsoft.Office.Interop.Word.Range myRange = wa.ActiveDocument.Range(ref zero, ref zero); object r = myRange; Microsoft.Office.Interop.Word.Paragraph p = wa.ActiveDocument.Paragraphs.Add(ref r); p.Range.InsertBefore(title); //p.Range.Font.Size = 1; Microsoft.Office.Interop.Word.Range titleRange = wa.ActiveDocument.Range(ref zero, ref titleLengh); //titleRange.Font.Size = 1; titleRange.Font.Name = "幼圆"; titleRange.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue; //MessageBox.Show("NO.1"); //titleRange.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; Microsoft.Office.Interop.Word.Range firstR = wa.ActiveDocument.Paragraphs[1].Range;//.Item(2).Range; Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(titleRange, 3, 3, ref Nothing, ref Nothing); r = firstR; p = wa.ActiveDocument.Paragraphs.Add(ref r); firstR.Font.Size = 40; firstR.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//在表格第一单元格中添加自定义的文字内容 table.Cell(1, 1).Range.Text = "lllll"; firstR.InsertAfter(first);//firstR.InsertParagraphAfter(); //firstR=wa.ActiveDocument.Paragraphs.Item(3).Range; firstR.InsertAfter(second); firstR.InsertAfter(third); firstR.InsertAfter(forth); firstR.InsertAfter(fifth); Context.Response.Write("成功");

如何做NPOI导出word

NPOI 2.0就可以了。

引用using NPOI.XWPF.UserModel;XWPFDocument doc = new XWPFDocument();doc.CreateParagraph();FileStream sw = File.OpenWrite("blank.docx");doc.Write(sw);sw.Close();追加一句,刚才是生成了一个文件,再用流的方式,提示客户端下载,即可/// /// 弹出提示框,提示用户是否下载保存到本地\/// /// 文件路径public static string openWindowExport(string strFileName){string strReutrn = "";try{FileInfo DownloadFile = new FileInfo(strFileName);System.Web.HttpContext.Current.Response.Clear();System.Web.HttpContext.Current.Response.ClearHeaders();System.Web.HttpContext.Current.Response.Buffer = false;System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+ System.Web.HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);}catch (Exception Ex){strReutrn = Ex.Message;}finally{System.Web.HttpContext.Current.Response.Flush();System.Web.HttpContext.Current.Response.End();}return strReutrn;

求教用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里配置好页面转向。

新建立的页面传值同查看页面要保持一样。

java 导出word格式设置 内容只读

protected void btndaochu1_Click(object sender, EventArgs e){Export("application/ms-excel", "学生资料报表.xls");}public void Export(string FileType, string FileName){Response.ClearContent();Response.Charset = "GB2312";Response.ContentEncoding = System.Text.Encoding.UTF7;Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());Response.ContentType = FileType;this.EnableViewState = false;StringWriter tw = new StringWriter();HtmlTextWriter hw = new HtmlTextWriter(tw);MyGridView.AllowPaging = false;MyGridView.Columns[10].Visible = false;MyGridView.Columns[0].Visible = false;bind();MyGridView.RenderControl(hw);Response.Write(tw.ToString());Response.End();MyGridView.AllowPaging = true;bind();}public override void VerifyRenderingInServerForm(Control control){}

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