jsp页面的按钮点击之后直接打印指定路径的word文件
试试下面这个方法:<%@page contentType="application/msword;charset=utf-8"%><%@page import="java.io.*"%><%String filename = "";if (request.getParameter("docfilename") != null) {filename = request.getParameter("docfilename");}
如何做jsp的时间控件?
上网去当个,有很多。
var h,m,s,hstr,mstr,sstr,timestr;var etime = 80 * 60; //总秒数function timer(){h = Math.floor(etime / 3600); //时m = Math.floor(etime / 60) % 60; //分s = Math.floor(etime % 60); //秒h m s h.toString().length m.toString().length s.toString().length timestr = hstr + ":" + mstr + ":" + sstr;txt.value = timestr;etime = etime - 1;}</script>
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;
(jsp)怎样实现把数据库的内容写入word文档?最好有个例子
在web-oa系统中,公文管理好象不可或缺,有时需要从数据库中查询一些数据以某种格式输出来,并以word文档的形式展现,有时许多word文档保存到数据库中的某个表的Blob字段里,服务器再把保存在Blob字段中的图片文件展现给用户。
通过网上查找发现很少有关于此类的文章,现在整理起来供大家参考。
1在client端直接生成word文档 在jsp页面上生成word文档非常简单,只需把contentType=”text/html”改为contentType="application/msword; charset=utf-8"即可,代码如下: 通过设置可以使原来页面的内容在word中表现出来。
如果需要把word文档下载下来,只需在jsp页面上面加上如下代码: 其中filename.doc中filename是要下载的word文档的文件名,可以通过来自行定制,如下 .doc"); %> 这样提供一个提示信息供用户选择如下图所示 小技巧:如果程序员需要在生成word文档的时候按照自己预先在word上设计好的格式,可以复制word格式然后粘贴到frontpage中,取html代码贴到jsp页面即可。
2 在客户端输出存在数据库中的word实体 这里只讨论在client输出oracle中BLOB字段中的word文档实体。
其中调用了类getBlobBean,该类提供了从oracle中取出blob功能,代码如下: package yourpackage; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import oracle.sql.*; import beans.yourbeanpackage. getBlobBean; /** * Title: * Description: * Copyright: Copyright (c) 2004 * Company: * @author not attributable * @version 1.0 */ public class GetBlobServlet1 extends HttpServlet { //设置输出内容类型,这个设置很重要,否则客户端浏览器不能识别输出内容,导致弹出下载的对话框。
private static final String CONTENT_TYPE = "application/msword;charset=utf-8"; //Initialize global variables public void init() throws ServletException { } //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); perform(request,response); } public void perform(HttpServletRequest request, HttpServletResponse response){ try{ //该类功能是从oracle哭中取出blob实体 getBlobBean getBlob=new getBlobBean(); OutputStream sos = response.getOutputStream(); getBlob.connFunction(); oracle.sql.BLOB blob=getBlob.getBlob("cehui"); //输出word文档 if(blob!=null){ InputStream pi = blob.getBinaryStream(); int blobsize =(int)blob.length(); byte[] blobbytes = new byte[blobsize]; int bytesRead = 0; while ((bytesRead = pi.read(blobbytes)) != -1) { sos.write(blobbytes, 0, bytesRead); } pi.close(); sos.flush(); sos.close(); } getBlob.dropConnFunction(); }catch(Exception e){ System.out.println(e.toString()); } } //Clean up resources public void destroy() { } } 3在client端直接生成EXCEL文档 生成 生成例子excel 。
用WORD排版面,倒出HTML 把代码拷贝到网页里,然后这个JSP页面打印你就随心所欲的控制了。
4在client端直接生成PDF文档 需要下载JAR包:以下代码在JDK1.4 RESIN2.16 下测试通过 ITEXT包 http://mesh.dl.sourceforge.net/sourceforge/itext/itext-1.3.5.jar 字体包 http://itext.sourceforge.net/downloads/iTextAsian.jar JSP生成到客户IE端直接打开 ie_PDF.jsp ------------------------------- 在服务器端生成不下载。
server_PDF.jsp <% String filename = "D:\\test\\111111.pdf" ; Document document = new Document(PageSize.A4); ServletOutputStream out1 = response.getOutputStream(); try{ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename) ); document.open(); document.add(new Paragraph("Hello World中文支持...
怎么在html中打开一个word
WORD使用控件后总是进入设计模式的问题解决办法2011-06-09 15:16今天在做WORD公文模板,其中用了几个复选框控件。
之前用的WORD2010,做完之后关闭设计模式,可以正常点选使用。
因为OFFICE2003-2007-2010之间有些兼容性问题,为确保这个模板的兼容性,在WORD2003里打开了这个模板,发现直接进入了设计模式,退出才能正常使用控件的功能。
网上搜的答案大都是把WORD宏的安全级别为“低”,只对本机有效,其他电脑上要再设置,不靠谱。
————————————————————————————————————找来找去,终于在百度里找到了一个正确答案,怕以后忘了,特此记下,也与有心人共享。
1、WORD模板加入控件设计完毕后,退出设计模式,保存为DOC2、另存为 RTF格式3、打开RTF文件,发现仍然是自动进入了设计模式,手动退出设计模式,保存4、另存为DOC格式,即为最终文件。
————————————————————————————————————这样得到的文件发给其他人,打开后不会触发宏提示或设计模式之类,可直接正常使用控件的功能。
WORD 2007和2010版做了优化,不存在上述问题,以上办法主要是考虑到大多数人还是习惯使用WORD 2003。
如何将jsp页面转化成word文档打印出来
可以利用table把试卷输出,然后利用JavaScript保存此表格为Word文档。
//下面代码为引用论坛其他人的回复,自己没测试过App为表格ID,你调用一下SaveAs函数. function PrintFile() { var strResult=window.confirm("确认用Word打印吗?"); if(strResult) { try { App.focus(); document.execCommand("SelectAll"); document.execCommand("Copy"); App.focus(); var WordApp=new ActiveXObject("Word.Application"); WordApp.Application.Visible=true; var Doc=WordApp.Documents.Add(); Doc.Activate(); Doc.Content.Paste(); Doc.PrintPreview(); WordApp.DisplayAlerts=false; Doc.Close(); WordApp.DisplayAlerts=true; WordApp.Quit(); } catch(e){} } else { var hwnd=window.open(""); hwnd.document.write(App.innerHTML); } return false; }
转载请注明出处51数据库 » jsp word控件