本文实例讲述了jsp实现针对excel及word文档的打印方法。分享给大家供大家参考,具体如下:
因为ms word和excel的文档都支持html文本格式,因此可以先用word或excel做好模版,另存为Web页,然后将该html改成jsp,将数据部分动态填入即可,不用很辛苦的调整格式
word页面只要在jsp头设置如下指令:
复制代码 代码如下:<%@page contentType="application/msword;charset=GBK" %>
excel如下:
复制代码 代码如下:<%@page contentType="application/vnd.ms-excel;charset=GBK" %>
使用这种方式客户端必须安装有office软件,用户访问时将在ie中直接用word或excel打开该页面。
此方法优势是模板设计、调整方便,无需在服务器端使用复杂的POI或jxl技术,也无需在客户端使用ActiveX控件技术,更安全、方便,轻松实现较好的打印效果。
microsoft关于服务器端动态创建office文档的资料(asp示例):
http://support.microsoft.com/default.aspx"htmlcode">
<%@ page contentType="application/msword;charset=GBK" %> <%@ page import="java.sql.*" %> <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=GB2312"> <meta name=ProgId content=Word.Document> <meta name=Generator content="Microsoft Word 9"> <meta name=Originator content="Microsoft Word 9"> <title>用户信息</title> <!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>evan zhao</o:Author> <o:LastAuthor>evan zhao</o:LastAuthor> <o:Revision>1</o:Revision> <o:TotalTime>1</o:TotalTime> <o:Created>2003-08-20T16:26:00Z</o:Created> <o:LastSaved>2003-08-20T16:27:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Company>taiping</o:Company> <o:Lines>1</o:Lines> <o:Paragraphs>1</o:Paragraphs> <o:Version>9.2812</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:PunctuationKerning> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:Compatibility> <w:SpaceForUL> <w:BalanceSingleByteDoubleByteWidth> <w:DoNotLeaveBackslashAlone> <w:ULTrailSpace> <w:DoNotExpandShiftReturn> <w:AdjustLineHeightInTable> <w:UseFELayout> </w:Compatibility> </w:WordDocument> </xml><![endif]--> <style> <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} --> </style> </head> <body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation'> <div class=Section1 style='layout-grid:15.6pt'> <table border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse; border:none;mso-border-alt:solid windowtext .5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'> <tr> <td width=189 valign=top style='width:142.0pt;border:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt'> <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman"'>用户名</span></p> </td> <td width=189 valign=top style='width:142.05pt;border:solid windowtext .5pt;border-left:none;mso-border-left-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'> <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman"'>真实姓名</span></p> </td> <td width=189 valign=top style='width:142.05pt;border:solid windowtext .5pt; border-left:none;mso-border-left-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'> <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman"; mso-hansi-font-family:"Times New Roman"'>性别</span></p> </td> </tr> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:mydb"; //连接mydb数据库 Connection con=DriverManager.getConnection (url, "", ""); try{ Statement stmt=con.createStatement(); //查询employee表 ResultSet rs=stmt.executeQuery("select user_name, real_name, gender from employee "); while(rs.next()){ %> <tr> <td width=189 valign=top style='width:142.0pt;border:solid windowtext .5pt;border-top:none;mso-border-top-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'> <p class=MsoNormal><span lang=EN-US><%=rs.getString("user_name")%></span></p> </td> <td width=189 valign=top style='width:142.05pt;border-top:none;border-left:none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'> <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'><%=rs.getString("real_name")%></span></p> </td> <td width=189 valign=top style='width:142.05pt;border-top:none;border-left:none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'> <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'><%=rs.getString("gender")%></span></p> </td> </tr> <% } // end while rs.close(); stmt.close(); } finally { con.close(); } %> </table> <p class=MsoNormal><span lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></span></p> </div> </body> </html>
希望本文所述对大家JSP程序设计有所帮助。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]