java库存导出_java生成导出excle文件
public void getExportExcle(List< Object > list,HttpServletResponse response) throws UnsupportedEncodingException {
//轉碼
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
String filename = new String("生成Excle.xls".getBytes("gb2312"),"ISO8859-1");
response.addHeader("Content-Disposition", "filename=" + filename);
//設置字體樣式
WritableFont wfont = new WritableFont(WritableFont.createFont("宋體"), 13, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
WritableCellFormat wcfFC = new WritableCellFormat(wfont);
Date date = new Date();
WritableWorkbook wwb = null;
try {
OutputStream os=response.getOutputStream();
//創建Excel工作表
wwb = Workbook.createWorkbook(os);
//創建sheet
WritableSheet ws = wwb.createSheet("庫存產品", 0);
//合并單元格(左列,左行,右列,右行)從第1行第1列到第2行第4列
ws.mergeCells(0, 0, 6, 1);
Label header = new Label(0, 0, "庫存產品", wcfFC);
ws.addCell(header);
ws.mergeCells(0, 2, 6, 2);
Label l = new Label(0, 2, "導出時間:"+date.toLocaleString());//第3列
ws.addCell(l);
l = new Label(0, 3, "倉庫編號", wcfFC );//第2行,第3列
ws.addCell(l);
l = new Label(1, 3, "倉庫名稱", wcfFC );//第2行,第2列
ws.addCell(l);
l = new Label(2, 3, "產品編號", wcfFC );//第2行,第4列
ws.addCell(l);
l = new Label(3, 3, "產品名稱", wcfFC );//第2行,第2列
ws.addCell(l);
l = new Label(4, 3, "當前庫存", wcfFC );//第2行,第4列
ws.addCell(l);
l = new Label(5, 3, "包裝單位", wcfFC );//第2行,第2列
ws.addCell(l);
l = new Label(6, 3, "包裝條碼", wcfFC);//第2行,第2列
ws.addCell(l);
ws.setColumnView(0,12);
ws.setColumnView(1,30);
ws.setColumnView(2,15);
ws.setColumnView(3,30);
ws.setColumnView(4,15);
ws.setColumnView(5,15);
ws.setColumnView(6,20);
for(int i=0;i
Object object=list.get(i);
if( object !=null){
l = new Label(0, i+4, "測試", wcfFC );//第2行,第1列
ws.addCell(l);
l = new Label(1, i+4, "測試", wcfFC );//第2行,第2列
ws.addCell(l);
l = new Label(2, i+4, "測試", wcfFC );//第2行,第3列
ws.addCell(l);
l = new Label(3, i+4, "測試", wcfFC );//第2行,第4列
ws.addCell(l);
l = new Label(4, i+4, "測試", wcfFC );//第2行,第5列
ws.addCell(l);
l = new Label(5, i+4, "測試", wcfFC );//第2行,第6列
ws.addCell(l);
l = new Label(6, i+4, "測試", wcfFC );//第2行,第7列
ws.addCell(l);
}
}
wwb.write();
wwb.close();
os.flush();
os.close();
}
catch (WriteException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的java库存导出_java生成导出excle文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java占用提示_Java显示使用或已经
- 下一篇: java委托机制教程_通过反射实现Jav