jxl导不出来_JXL导出及添加批注实战

导出效果:

//使用submit或a标签访问导出方法,千万不能用ajax,不刷新就不会出现下载框哦

//省略方法名接参查询等等操作

response.setContentType("application/msexcel");

response.setHeader("Content-disposition", "attachment; filename=export.xls");

OutputStream os = response.getOutputStream(); //获取输出流

doExportStudents(os, list); //调用导出方法,list是参数值

os.flush();

os.close();

os = null;

return null;

//导出方法

public void doExportStudents(OutputStream os, List list){

try {

WritableWorkbook wbook = Workbook.createWorkbook(os); // 建立excel文件

WritableSheet wsheet = wbook.createSheet("培训班导入",

0); // sheet名称

WritableFont bold = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);

WritableCellFormat wcfFormat = new WritableCellFormat(bold);

wcfFormat.setAlignment(jxl.format.Alignment.CENTRE);//单元格中的内容水平方向居中

//把垂直对齐方式指定为居中

wcfFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

wcfFormat.setBorder(Border.ALL, BorderLineStyle.THIN);

int rowIndex = 0; //行

int columnIndex = 0; //列

//第一行

columnIndex = 0;

rowIndex = 0 ;

wsheet.addCell(new Label(0, rowIndex, "培训班编号",wcfFormat));//

wsheet.addCell(new Label(1, rowIndex, "学员编号",wcfFormat));//

wsheet.addCell(new Label(2, rowIndex, "学员姓名",wcfFormat));//

//未结训状态添加批注

WritableCellFeatures cellFeatures = new WritableCellFeatures();

cellFeatures.setComment("请输入1或2\r\n1:未结训\r\n2:结训");

Label label = new Label(3, rowIndex, "学员结训状态",wcfFormat);

label.setCellFeatures(cellFeatures);

wsheet.addCell(label);//学员结训状态加批注

wsheet.addCell(new Label(4, rowIndex, "备注",wcfFormat));//

//填写数据

// lResult2 设计成序号

WritableCellFormat wcfFormat123 = new WritableCellFormat();

//单元格中的内容垂直方向居中

wcfFormat123.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);

wcfFormat123.setBorder(Border.ALL, BorderLineStyle.THIN);

// 二行

columnIndex = 0;

rowIndex = 1;

for(int i=0;i

ITrainingClassVOModel model = list.get(i);

wsheet.addCell(new Label(columnIndex++,rowIndex

,model.getClass_id(),wcfFormat123));

wsheet.addCell(new Label(columnIndex++,rowIndex

,model.getPerson_id(),wcfFormat123));

wsheet.addCell(new Label(columnIndex++,rowIndex

,model.getPerson_name(),wcfFormat123));

columnIndex = 0;

rowIndex++;

}

wbook.write();

if (wbook != null) {

wbook.close();

}

} catch (Exception e) {

e.printStackTrace();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值