WritableWorkbook 导出EXCEL

来源:互联网 发布:阿克苏新站怎么做优化 编辑:程序博客网 时间:2024/06/06 00:58
感觉比POI简单请口味多了
 
public void exportPvDetail(List list,OutputStream sos, HttpServletRequest request)throws Exception{    WritableWorkbook wwb = Workbook.createWorkbook(sos);WritableSheet ws = wwb.createSheet("sheet1", 0);// 标题样式WritableFont font = new WritableFont(WritableFont.TAHOMA, 9, WritableFont.BOLD);// 定义字体    font.setColour(Colour.BLACK);// 字体颜色    WritableCellFormat wc = new WritableCellFormat(font);wc.setAlignment(Alignment.CENTRE); // 设置左对齐wc.setBorder(Border.ALL, BorderLineStyle.THIN); // 设置边框线wc.setBackground(jxl.format.Colour.YELLOW); // 设置单元格的背景颜色WritableFont font2 = new WritableFont(WritableFont.TAHOMA, 9, WritableFont.NO_BOLD);// 定义字体WritableCellFormat wc2 = new WritableCellFormat(font2);wc2.setBorder(Border.ALL, BorderLineStyle.THIN); // 设置边框线ws.addCell(new Label(0, 0, "abc",wc));ws.addCell(new Label(1, 0, "efg",wc));ws.addCell(new Label(2, 0, "",wc));int colCount = 2;// 列数int rowCount = list != null ? list.size() : 0;// 行数for (int i = 0; i <rowCount; i++) {ws.addCell(new Label(0, i+1,(String)((Object[])list.get(i))[0],wc2)); //列-行-值ws.addCell(new Label(1, i+1,(String)((Object[])list.get(i))[1],wc2)); //列-行-值ws.addCell(new Label(2, i+1,(String)((Object[])list.get(i))[2],wc2)); //列-行-值ws.setColumnView(0, 15);// 设置列宽2}wwb.write();wwb.close();    }

健忘者的脑图,步骤:

原创粉丝点击