jsp導(dǎo)出為word文檔的幾個(gè)技巧關(guān)鍵字: jsp導(dǎo)出為word文檔的幾個(gè)技巧寫(xiě)道
1、步驟:
第一步:編輯好word模版,然后另存為*.htm,比如:liukun.htm。 技巧:在需要填寫(xiě)數(shù)據(jù)的地方最好預(yù)填入一些易識(shí)別的數(shù)據(jù),這樣方便后面填寫(xiě)jsp代碼。 第二步:把htm后綴改為jsp,比如:liukun.jsp。 第三步:添加jsp的頭,比如: <%@page contentType="application/msword;charset=GBK"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> 如果有import,也要在這里導(dǎo)入。 技巧:application/msword;這個(gè)參數(shù)很重要,有了這個(gè)參數(shù),調(diào)用這個(gè)頁(yè)面時(shí),就會(huì)把頁(yè)面內(nèi)容存為word。當(dāng)然,本地必須安裝office。 第三步:添加jsp標(biāo)簽。(我用的是struts框架,所以添加的是struts的標(biāo)簽,也可以添加<%%>) ...... <logic:present name="liukun" scope="request"> ...... <bean:write name="liukun" property="xm" scope="request" /> ...... </logic:present> ...... 當(dāng)然,也可以加循環(huán),這樣生成多頁(yè)(份): ...... <logic:notEmpty name="bmklist" scope="request"> <logic:iterate id="examManage" name="bmklist" type="ujn.ems.liukun.Info" scope="request"> ...... <bean:write name="examManage" property="xm" scope="page" /> ...... </logic:iterate> </logic:notEmpty> ...... 第四步:寫(xiě)action,把查詢(xún)數(shù)據(jù)庫(kù)后的結(jié)果通過(guò)request給頁(yè)面?zhèn)鲄?shù)。 ...... public ActionForward saveZY2word(ActionMapping mapping, ActionForm. form, HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub ArrayList<Info> bmklist = new ArrayList<Info>(); String bkzydm = request.getParameter("bkzydm"); bmklist = Info.listAllInfobyZY(bkzydm); if(bmklist!=null){ request.setAttribute("bmklist",bmklist); return mapping.findForward("saveAll2word"); } return null; } ...... 2、其他技巧(別人我不告訴他啊,呵呵): A、橫向頁(yè)面導(dǎo)出: <style> <!-- ...... /* Page Definitions */ @page Section1 {size:841.9pt 595.3pt; mso-page-orientation:landscape; margin:89.85pt 72.0pt 89.85pt 3.0cm; layout-grid:15.6pt;} div.Section1 {page:Section1;} --> </style> B、分頁(yè): ...... <span lang=EN-US style='font-size:10.5pt;font-family:黑體;mso-hansi-font-family: "Times New Roman";mso-bidi-font-family:"Times New Roman";mso-ansi-language: EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'><br clear=all style='mso-special-character:line-break;page-break-before:always'> </span> ...... C、縮小字體填充: ...... <td width=84 nowrap valign=top style='width:63.0pt;border-top:none; border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt;text-fit:100%;height:19.65pt'> <p class=MsoNormal align=center style='text-align:center'> <span style='font-family:宋體;color:black;letter-spacing:.75pt'> <bean:write name="examManage" property="xm" scope="page" /> </span> </p> </td> ...... |
|
來(lái)自: hrkflying > 《編程學(xué)習(xí)》