public class ExportExcelUtil {
/**
* 生成Excel表格
*
* @author:
* @CreateDate: 2019/5/8 9:35
*
* @Modifier
* @ModifyData
* @ModifyDescription 描述修改內(nèi)容
* @param [workbook, sheetNum, sheetTitle, headers, result]
* @return void
* @throws
*/
public static void exportExcel(HSSFWorkbook workbook, int sheetNum, String sheetTitle,
String[] headers, List<List<String>> result) {
// 生成一個表格
HSSFSheet sheet = workbook.createSheet();
workbook.setSheetName(sheetNum, sheetTitle);
// 設置表格默認列寬度為20個字節(jié)
sheet.setDefaultColumnWidth(20);
// 生成一個樣式
HSSFCellStyle style = workbook.createCellStyle();
// 設置以下樣式
style.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 生成一個字體
HSSFFont font = workbook.createFont();
font.setColor(HSSFColor.BLACK.index);
font.setFontHeightInPoints((short) 12);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// 把字體應用到當前的樣式
style.setFont(font);
// 指定當單元格內(nèi)容顯示不下時自動換行
style.setWrapText(true);
// 產(chǎn)生表格標題行
HSSFRow row = sheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
HSSFCell cell = row.createCell(i);
cell.setCellStyle(style);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text.toString());
}
// 遍歷集合數(shù)據(jù),產(chǎn)生數(shù)據(jù)行
if (result != null) {
int index = 1;
for (List<String> m : result) {
row = sheet.createRow(index);
int cellIndex = 0;
for (String str : m) {
HSSFCell cell = row.createCell(cellIndex);
cell.setCellValue(str);
cellIndex++;
}
index++;
}
}
}
}
Excel導出多個sheet表格
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關閱讀更多精彩內(nèi)容
- 要完成導出樣式如下圖導出報表excel格式.png 1-4行:標題 5-12行:項目的基本信息 inputProD...
- 前面兩篇文章已經(jīng)介紹了POI導出表格的基本使用、常見excel的導出。使用HSSFWorkbook導出、操作exc...
- 導出excel的邏輯: excel整個表格專業(yè)名詞是workbook,里面每張表格是sheet 頁面引入xlsx的...
- Microsoft Sql Server Report 將多個組合成1個,導出帶excel sheet 1.子報表...
- 最近幾天因為項目需要做一個導出導出表格數(shù)據(jù)到Excel功能,我們的項目的前端框架用的是Bootstrap Tabl...