java导出excel 序号_Java 实现导出excel表
/**
* 導出出險信息 fc
*
* @param jzForm
* ? ? ? ? ? ?查詢條件
* @param sessionUser
* ? ? ? ? ? ?當前登錄session用戶
* @param errors
* ? ? ? ? ? ?Action錯誤
* @return
*/
public void exprotAcExcel(List list, String path,HttpServletRequest request) {
try {
WritableWorkbook workbook = Workbook.createWorkbook(new File(path));// 創建工作簿(filePos為excel文件的路徑)
WritableSheet sheet = workbook.createSheet("出險信息", 0);// 創建工作頁
// 內容(居中)單元格樣式
WritableCellFormat contentStyle = new WritableCellFormat(); //
contentStyle.setAlignment(jxl.format.Alignment.CENTRE); // 設置對齊方式
contentStyle.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN); // 設置邊框
// 一級標題單元格樣式
WritableFont wf1 = new WritableFont(WritableFont.ARIAL, 15,
WritableFont.BOLD, false); // 定義格式 字體 下劃線 斜體 粗體 顏色
WritableCellFormat titleStyle1 = new WritableCellFormat(wf1); //
titleStyle1.setBackground(jxl.format.Colour.GREEN); // 設置單元格的背景顏色
titleStyle1.setAlignment(jxl.format.Alignment.CENTRE); // 設置對齊方式
titleStyle1.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN); // 設置邊框
// 二級標題單元格樣式
WritableFont wf2 = new WritableFont(WritableFont.ARIAL, 11,
WritableFont.BOLD, false); // 定義格式 字體 下劃線 斜體 粗體 顏色
WritableCellFormat titleStyle2 = new WritableCellFormat(wf2); //
titleStyle2.setBackground(jxl.format.Colour.GREY_25_PERCENT); // 設置單元格的背景顏色
titleStyle2.setAlignment(jxl.format.Alignment.CENTRE); // 設置水平對齊方式
titleStyle2
.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); // 設置垂直對齊方式
titleStyle2.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN); // 設置邊框
WritableCellFormat titleStyle3 = new WritableCellFormat(wf1); //
titleStyle3.setBackground(jxl.format.Colour.BRIGHT_GREEN); // 設置單元格的背景顏色
titleStyle3.setAlignment(jxl.format.Alignment.CENTRE); // 設置對齊方式
titleStyle3.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN); // 設置邊框
// 設置凍結單元格
sheet.getSettings().setVerticalFreeze(2);
sheet.getSettings().setHorizontalFreeze(5);
sheet.setColumnView(0, 8); // 設置列的寬度
sheet.setColumnView(1, 10); // 設置列的寬度
sheet.setRowView(0, 0);
sheet.addCell(new Label(0, 0, "hysj5800294*#", titleStyle1));// 標題
sheet.addCell(new Label(0, 1, "出險信息 ", titleStyle2));// 標題
sheet.mergeCells(0, 2, 33, 2); // 合并單元格
sheet.addCell(new Label(0, 2, "出險信息 ", titleStyle1));// 標題
sheet.addCell(new Label(0, 3, "序號", titleStyle2));// 往單元格中填寫數據
sheet.addCell(new Label(1, 3, "省內/省外", titleStyle2));// 往單元格中填寫數據
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
sheet.setRowView(i + 3, 300); // 設置行高
//轉換數據信息
//Object[] obj = (Object[]) list.get(i);
AccidentRecord ar = (AccidentRecord) list.get(i);
sheet.addCell(new Label(0, i + 4, String.valueOf(i + 1),contentStyle));// 往單元格中填寫數據 序號
sheet.addCell(new Label(1, i + 4, ar.getLicenceProvince().toString(),contentStyle));// ?省內/省外
}
}
workbook.write();// 書寫到工作簿
workbook.close();// 關閉工作簿,輸出完成
} catch (Exception e) {
e.printStackTrace();
}
}
}
總結
以上是生活随笔為你收集整理的java导出excel 序号_Java 实现导出excel表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于SSM框架的狼途汽车门店管理系统的设
- 下一篇: java美元兑换,(Java实现) 美元