<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    piliskys

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      25 隨筆 :: 0 文章 :: 40 評(píng)論 :: 0 Trackbacks
         jsp導(dǎo)出excel有很多種方法,在此介紹本人認(rèn)為簡(jiǎn)單的一種,
    前提:能在jsp頁(yè)面取到要導(dǎo)出的內(nèi)容,即 request能得到導(dǎo)出的數(shù)據(jù),然后代碼如下
    <%@ page language="java" contentType="text/html;charset=gb2312"%>
    <%@ page language="java"  import="java.util.*,
                                      org.apache.poi.hssf.usermodel.HSSFWorkbook,
                                      org.apache.poi.hssf.usermodel.HSSFSheet,
                                      org.apache.poi.hssf.usermodel.HSSFRow,
                                      org.apache.poi.hssf.usermodel.HSSFCell,
                                      java.text.DecimalFormat
    "
    %>
    <%
        response.reset();
        response.setContentType(
    "application/msexcel");
        response.setHeader(
    "Content-disposition","inline;filename=untitled.xls");//定義文件名
        DecimalFormat f 
    = new DecimalFormat("#,##0.00");
        HSSFWorkbook wb 
    = new HSSFWorkbook();
        HSSFSheet sheet 
    = wb.createSheet("sheet1");
        
    String[] taxpayerid = request.getParameterValues("taxpayerid");
        
    String[] taxpayername = request.getParameterValues("taxpayername");
        
    String[] tax = request.getParameterValues("tax");
        
    String[] taxreduce = request.getParameterValues("taxreduce");
        
    String[] deratereasonname = request.getParameterValues("deratereasonname");
        
    String[] orgdeptname = request.getParameterValues("orgdeptname");
        
    String[] operatortime = request.getParameterValues("operatortime");
        
    String[] declaredate = request.getParameterValues("declaredate");
        
    String[] taxtermbegin = request.getParameterValues("taxtermbegin");
        
    String[] taxtermend = request.getParameterValues("taxtermend");

    //以下以寫表頭
            
    //表頭為第一行
          HSSFRow row 
    = sheet.createRow((short) 0);
    //定義10列
             HSSFCell cell1 
    = row.createCell((short) 0);
            HSSFCell cell2 
    = row.createCell((short) 1);
            HSSFCell cell3 
    = row.createCell((short) 2);
            HSSFCell cell4 
    = row.createCell((short) 3);
            HSSFCell cell5 
    = row.createCell((short) 4);
            HSSFCell cell6 
    = row.createCell((short) 5);
            HSSFCell cell7 
    = row.createCell((short) 6);
            HSSFCell cell8 
    = row.createCell((short) 7);
            HSSFCell cell9 
    = row.createCell((short) 8);
            HSSFCell cell10 
    = row.createCell((short) 9);

            cell1.setEncoding((short) 
    1);
            cell1.setCellType(
    1);
            cell2.setEncoding((short) 
    1);
            cell2.setCellType(
    1);
            cell3.setEncoding((short) 
    1);
            cell3.setCellType(
    1);
            cell4.setEncoding((short) 
    1);
            cell4.setCellType(
    1);
            cell5.setEncoding((short) 
    1);
            cell5.setCellType(
    0);
            cell6.setEncoding((short) 
    1);
            cell6.setCellType(
    1);
            cell7.setEncoding((short) 
    1);
            cell7.setCellType(
    1);
            cell8.setEncoding((short) 
    1);
            cell8.setCellType(
    1);
            cell9.setEncoding((short) 
    1);
            cell9.setCellType(
    1);
            cell10.setEncoding((short) 
    1);
            cell10.setCellType(
    1);
    //定義表頭的內(nèi)容
            cell1.setCellValue(
    "納稅人管理碼");
            cell2.setCellValue(
    "納稅人名稱");
            cell3.setCellValue(
    "稅種");
            cell4.setCellValue(
    "減免金額");
            cell5.setCellValue(
    "減免原因");
            cell6.setCellValue(
    "征收單位");
            cell7.setCellValue(
    "操作日期");
            cell8.setCellValue(
    "申報(bào)日期");
            cell9.setCellValue(
    "所屬期起");
            cell10.setCellValue(
    "所屬期止");


        
    for(int i= 0; i < taxpayerid.length; i++){
    //定義數(shù)據(jù)從第二行開(kāi)始       
      row 
    = sheet.createRow((short) i+1);
                    cell1 
    = row.createCell((short) 0);
                    cell2 
    = row.createCell((short) 1);
                    cell3 
    = row.createCell((short) 2);
                    cell4 
    = row.createCell((short) 3);
                    cell5 
    = row.createCell((short) 4);
                    cell6 
    = row.createCell((short) 5);
                    cell7 
    = row.createCell((short) 6);
                    cell8 
    = row.createCell((short) 7);
                    cell9 
    = row.createCell((short) 8);
                    cell10 
    = row.createCell((short) 9);

                   cell1.setEncoding((short) 
    1);
                   cell1.setCellType(
    1);
                   cell2.setEncoding((short) 
    1);
                   cell2.setCellType(
    1);
                   cell3.setEncoding((short) 
    1);
                   cell3.setCellType(
    1);
                   cell4.setEncoding((short) 
    1);
                   cell4.setCellType(
    1);
                   cell5.setEncoding((short) 
    1);
                   cell5.setCellType(
    0);
                   cell6.setEncoding((short) 
    1);
                   cell6.setCellType(
    1);
                   cell7.setEncoding((short) 
    1);
                   cell7.setCellType(
    1);
                   cell8.setEncoding((short) 
    1);
                   cell8.setCellType(
    1);
                   cell9.setEncoding((short) 
    1);
                   cell9.setCellType(
    1);
                   cell10.setEncoding((short) 
    1);
                   cell10.setCellType(
    1);

    //填充內(nèi)容

            cell1.setCellValue(taxpayerid[i]);
            cell2.setCellValue(taxpayername[i]);
            cell3.setCellValue(tax[i]);
            cell4.setCellValue(f.parse(taxreduce[i].trim()).doubleValue());
            cell5.setCellValue(deratereasonname[i]);
            cell6.setCellValue(orgdeptname[i]);
            cell7.setCellValue(operatortime[i].substring(
    0,16));
            cell8.setCellValue(declaredate[i].substring(
    0,16));
            cell9.setCellValue(taxtermbegin[i].substring(
    0,16));
            cell10.setCellValue(taxtermend[i].substring(
    0,16));
        }
        wb.write(response.getOutputStream());
        response.getOutputStream().flush();
        response.getOutputStream().close();
    %>


    代碼比較簡(jiǎn)單,首先把取得到的數(shù)據(jù)定義為一系列數(shù)組,然后定義表頭,然后把取得的數(shù)據(jù)做為excel數(shù)據(jù)對(duì)應(yīng)的放入,對(duì)poi有何疑問(wèn)請(qǐng)參考http://java2.5341.com/3.html
    posted on 2005-11-23 10:27 霹靂火 閱讀(11714) 評(píng)論(12)  編輯  收藏

    評(píng)論

    # re: jsp導(dǎo)出excel 2006-02-15 08:37 ts
    你們自己測(cè)過(guò)嗎,報(bào)錯(cuò):
    Note: sun.tools.javac.Main has been deprecated.
    /fdtj/test.jsp:11: Class org.apache.poi.hssf.usermodel.HSSFWorkbook not
    found in import.
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    ^
    /fdtj/test.jsp:12: Class org.apache.poi.hssf.usermodel.HSSFSheet not found
    in import.
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    ^
    /fdtj/test.jsp:13: Class org.apache.poi.hssf.usermodel.HSSFRow not found
    in import.
    import org.apache.poi.hssf.usermodel.HSSFRow;
    ^
    /fdtj/test.jsp:14: Class org.apache.poi.hssf.usermodel.HSSFCell not found
    in import.
    import org.apache.poi.hssf.usermodel.HSSFCell;
      回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2006-02-15 11:00 霹靂火
    如果我沒(méi)測(cè)試過(guò)我就不會(huì)發(fā)上來(lái),樓上的你自己沒(méi)有導(dǎo)入包,這種應(yīng)該算你的失誤啊  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2006-03-08 14:39 請(qǐng)問(wèn),這是什么故障啊?
    exception

    org.apache.jasper.JasperException
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    root cause

    java.lang.NullPointerException
    org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:116)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    請(qǐng)問(wèn),這是什么故障啊?  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2006-03-10 14:24 霹靂火
    NullPointerException 你要確保你的參數(shù)能從頁(yè)面上取到值,所以必須為input,提交后要能由request得到,可能是你的沒(méi)有得到值   回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2006-07-10 21:26 jsp郁悶者
    如何同時(shí)設(shè)置excel的紙張為橫向?  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2008-01-02 10:16
    哪可以下POI的JAR文件  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2008-04-07 00:32 BinTime
    很好,找了好久了!  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2008-04-21 11:06 cfhjava
    為什么我的是亂碼了。<%@ page language="java" contentType="text/html;charset=utf-8"%>
    我是JSP的。請(qǐng)幫!  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel[未登錄](méi) 2008-12-20 23:22 JAVA
    OK,正在找....  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2008-12-28 00:51 mya
    String[] taxtermend = request.getParameterValues("taxtermend");
    請(qǐng)問(wèn)右邊這個(gè)taxtermend是頁(yè)面上表格的ID還是什么名稱?  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2009-05-31 08:42 guest
    <%@ page language="java" contentType="text/html;charset=GBK"%>
    這樣就OK  回復(fù)  更多評(píng)論
      

    # re: jsp導(dǎo)出excel 2009-06-08 11:47 文東
    這個(gè)東西是怎么去調(diào)用的啊  回復(fù)  更多評(píng)論
      


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲高清专区日韩精品| 青娱分类视频精品免费2| 视频一区在线免费观看| 国产成人人综合亚洲欧美丁香花 | 女人18毛片水真多免费播放| 青青在线久青草免费观看| 午夜性色一区二区三区免费不卡视频| 最近中文字幕免费完整| 2019中文字幕免费电影在线播放| 99久久综合精品免费| 永久免费视频网站在线观看| 国产精品色拉拉免费看| 毛片A级毛片免费播放| 免费看香港一级毛片| 国产成人免费手机在线观看视频| 国产免费黄色大片| 免费在线观看黄网站| 亚洲片国产一区一级在线观看| 久久久久亚洲精品男人的天堂| 国产自偷亚洲精品页65页| 国产亚洲人成网站观看| 亚洲免费在线播放| 亚洲国产高清美女在线观看| 亚洲欧洲日本在线观看| 国产成人亚洲午夜电影| a级毛片免费观看网站| 久久国产乱子精品免费女| 2019中文字幕在线电影免费| 在线观看人成视频免费| 亚洲av片一区二区三区| 亚洲国产另类久久久精品黑人| 亚洲AV无码精品色午夜果冻不卡 | 亚洲伦理中文字幕| 国产精品亚洲专区无码牛牛| 在线播放国产不卡免费视频| 18禁在线无遮挡免费观看网站| 97青青草原国产免费观看| 67194成是人免费无码| 免费在线观看一级毛片| 国产V亚洲V天堂A无码| 亚洲大尺码专区影院|