博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jxl.jar 导出excel
阅读量:5249 次
发布时间:2019-06-14

本文共 3217 字,大约阅读时间需要 10 分钟。

 <%@ page pageEncoding="utf-8" %>

<%@ page language="java" contentType="text/html; charset=GBK" %><%@ page import="java.util.*" %>
<%@ page import="java.io.OutputStream" %>

<%@ page import="jxl.Workbook" %>

<%@ page import="jxl.write.WritableCellFormat" %>
<%@ page import="jxl.write.WritableSheet" %>
<%@ page import="jxl.write.WritableWorkbook" %>
<%@ page import="jxl.write.WriteException" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%  
    response.reset();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "filename=Member.xls");//attachment// WritableWorkbook是JexcelApi的一个类。
// 以下可以理解为创建一个excel文件,然后在excel里面创建一个表
    OutputStream os = response.getOutputStream();//取得输出流
    WritableWorkbook workbook = Workbook.createWorkbook(os);
    WritableSheet sheet = workbook.createSheet("First Sheet", 0);// 组织excel文件的内容
    jxl.write.Label label = null;
    int excelCol = 0;
    int row = 0;
    try {
        label = new jxl.write.Label(excelCol++, row, "帐号");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "姓名");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "身份证");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "联系电话");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "生日");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "城市");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "职业");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "已购音箱型号");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "试听与否");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol++, row, "邮箱");
        sheet.addCell(label);
        label = new jxl.write.Label(excelCol, row, "注册时间");
        sheet.addCell(label);
        //jxl.write.Number number = null;
        jxl.write.DateTime dateTime;
        jxl.write.DateFormat customDateFormat = new jxl.write.DateFormat("yyyy-MM-dd");//时间格式
        WritableCellFormat dateFormat = new WritableCellFormat(customDateFormat);        for(int i=0;i<10;i++){
            excelCol = 0;
            row = i + 1;            SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");     
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            /*字串格式*/
            try{
                label = new jxl.write.Label(excelCol++, row, formatDate.format("100"));
                sheet.addCell(label);
            }catch (Exception e){
                //Maybe somebody fogot to input his birthday ,I need do nothing here!
            }            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            label = new jxl.write.Label(excelCol++, row, "100");
            sheet.addCell(label);            /*时间格式*/
         
                    //label = new jxl.write.Label(excelCol, row, formatDate.format(rr.getCreateTime()));
            //sheet.addCell(label);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally{
//      生成excel文件
        workbook.write();
        workbook.close();
        os.close();
    }
%>
  

转载于:https://www.cnblogs.com/wshsdlau/archive/2012/08/23/2653279.html

你可能感兴趣的文章
Nginx配置文件(nginx.conf)配置详解1
查看>>
linux php编译安装
查看>>
redis哨兵集群、docker入门
查看>>
hihoCoder 1233 : Boxes(盒子)
查看>>
codeforces水题100道 第二十二题 Codeforces Beta Round #89 (Div. 2) A. String Task (strings)
查看>>
c++||template
查看>>
[BZOJ 5323][Jxoi2018]游戏
查看>>
条件断点 符号断点
查看>>
Python Web框架Django (五)
查看>>
.net学习之继承、里氏替换原则LSP、虚方法、多态、抽象类、Equals方法、接口、装箱拆箱、字符串------(转)...
查看>>
python的多行注释
查看>>
连接Oracle需要jar包和javadoc文档的下载
查看>>
UVA 10976 - Fractions Again?!
查看>>
Dreamweaver cc新版本css单行显示
查看>>
【android】安卓的权限提示及版本相关
查看>>
JavaScript可否多线程? 深入理解JavaScript定时机制
查看>>
IOS基础学习
查看>>
Java基础教程——网络基础知识
查看>>
Kruskal基础最小生成树
查看>>
浅谈算法和数据结构: 一 栈和队列
查看>>