List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet setDefaultRowHeight
@Override public void setDefaultRowHeight(short height)
From source file:com.dv.util.DVExcelIO.java
License:Open Source License
public static boolean exportIntoExcel(String fullExcelFileName, String sheetName, Vector cols, Vector rows) { boolean isExportFine = true; HSSFWorkbook hsswb = null;//from ww w .ja va2 s.com HSSFSheet hsssh = null; HSSFRow row = null; try { File excel = new File(fullExcelFileName); if (!excel.exists()) { hsswb = new HSSFWorkbook(); hsssh = hsswb.createSheet(sheetName); hsssh.setDefaultRowHeight((short) 10); hsssh.setDefaultColumnWidth(20); } else { hsswb = new HSSFWorkbook(new FileInputStream(excel)); hsssh = hsswb.createSheet(sheetName); hsssh.setDefaultRowHeight((short) 10); hsssh.setDefaultColumnWidth(20); } row = hsssh.createRow((short) 2); HSSFCellStyle style = hsswb.createCellStyle(); style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.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.setBottomBorderColor(HSSFColor.BLACK.index); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setTopBorderColor(HSSFColor.BLACK.index); style.setRightBorderColor(HSSFColor.BLACK.index); for (int i = 0; i < cols.size(); i++) { HSSFCell cell = row.createCell(i); cell.setCellValue(cols.get(i).toString()); cell.setCellStyle(style); } HSSFCellStyle style1 = hsswb.createCellStyle(); style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); style1.setBorderLeft(HSSFCellStyle.BORDER_THIN); style1.setBorderRight(HSSFCellStyle.BORDER_THIN); style1.setBorderTop(HSSFCellStyle.BORDER_THIN); style1.setBottomBorderColor(HSSFColor.BLACK.index); style1.setLeftBorderColor(HSSFColor.BLACK.index); style1.setTopBorderColor(HSSFColor.BLACK.index); style1.setRightBorderColor(HSSFColor.BLACK.index); for (int i = 3; i <= rows.size() + 2; i++) { row = hsssh.createRow((short) i); for (int j = 0; j < cols.size(); j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(((Vector) rows.elementAt(i - 3)).get(j).toString()); cell.setCellStyle(style1); } } FileOutputStream fOut = new FileOutputStream(excel); hsswb.write(fOut); fOut.flush(); fOut.close(); } catch (IOException e) { DVLOG.setErrorLog(DVExcelIO.class.getName(), e); return false; } catch (IllegalArgumentException e) { DVLOG.setErrorLog(DVExcelIO.class.getName(), e); return false; } catch (Exception e) { DVLOG.setErrorLog(DVExcelIO.class.getName(), e); return false; } return isExportFine; }
From source file:com.dv.util.DVExcelIO.java
License:Open Source License
public static boolean exportBatchResultIntoExcel(String fullExcelFileName, String sheetName, HashMap<String, Vector> colsMap, HashMap<String, Vector> rowsMap) { HSSFWorkbook hsswb = null;//from w ww . j a v a 2s . com HSSFSheet hsssh = null; HSSFRow row = null; Vector cols = new Vector(); Vector rows = new Vector(); try { File excel = new File(fullExcelFileName); if (!excel.exists()) { hsswb = new HSSFWorkbook(); hsssh = hsswb.createSheet(sheetName); hsssh.setDefaultRowHeight((short) 10); hsssh.setDefaultColumnWidth(20); } else { hsswb = new HSSFWorkbook(new FileInputStream(excel)); hsssh = hsswb.createSheet(sheetName); hsssh.setDefaultRowHeight((short) 10); hsssh.setDefaultColumnWidth(20); } int rowCount = 1; for (int k = 0; k < colsMap.size(); k++) { cols = colsMap.get(String.valueOf(k)); rows = rowsMap.get(String.valueOf(k)); rowCount = rowCount + 1; row = hsssh.createRow((short) (rowCount)); HSSFCellStyle style = hsswb.createCellStyle(); style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.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.setBottomBorderColor(HSSFColor.BLACK.index); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setTopBorderColor(HSSFColor.BLACK.index); style.setRightBorderColor(HSSFColor.BLACK.index); for (int i = 0; i < cols.size(); i++) { HSSFCell cell = row.createCell(i); cell.setCellValue(cols.get(i).toString()); cell.setCellStyle(style); } HSSFCellStyle style1 = hsswb.createCellStyle(); style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); style1.setBorderLeft(HSSFCellStyle.BORDER_THIN); style1.setBorderRight(HSSFCellStyle.BORDER_THIN); style1.setBorderTop(HSSFCellStyle.BORDER_THIN); style1.setBottomBorderColor(HSSFColor.BLACK.index); style1.setLeftBorderColor(HSSFColor.BLACK.index); style1.setTopBorderColor(HSSFColor.BLACK.index); style1.setRightBorderColor(HSSFColor.BLACK.index); int loop = rowCount; for (int i = 1 + loop; i <= rows.size() + loop; i++) { row = hsssh.createRow((short) i); for (int j = 0; j < cols.size(); j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(((Vector) rows.elementAt(i - (1 + loop))).get(j).toString()); cell.setCellStyle(style1); } rowCount++; } } FileOutputStream fOut = new FileOutputStream(excel); hsswb.write(fOut); fOut.flush(); fOut.close(); } catch (IOException e) { DVLOG.setErrorLog(DVExcelIO.class.getName(), e); return false; } catch (IllegalArgumentException e) { DVLOG.setErrorLog(DVExcelIO.class.getName(), e); return false; } catch (Exception e) { DVLOG.setErrorLog(DVExcelIO.class.getName(), e); return false; } return true; }
From source file:com.eryansky.core.excelTools.ExcelUtils.java
License:Apache License
public static void copySheetStyle(HSSFWorkbook destwb, HSSFSheet dest, HSSFWorkbook srcwb, HSSFSheet src) { if (src == null || dest == null) return;//from w w w . j a v a2 s . c om dest.setAlternativeExpression(src.getAlternateExpression()); dest.setAlternativeFormula(src.getAlternateFormula()); dest.setAutobreaks(src.getAutobreaks()); dest.setDialog(src.getDialog()); if (src.getColumnBreaks() != null) { for (int col : src.getColumnBreaks()) { dest.setColumnBreak(col); } } dest.setDefaultColumnWidth(src.getDefaultColumnWidth()); dest.setDefaultRowHeight(src.getDefaultRowHeight()); dest.setDefaultRowHeightInPoints(src.getDefaultRowHeightInPoints()); dest.setDisplayGuts(src.getDisplayGuts()); dest.setFitToPage(src.getFitToPage()); dest.setHorizontallyCenter(src.getHorizontallyCenter()); dest.setDisplayFormulas(src.isDisplayFormulas()); dest.setDisplayGridlines(src.isDisplayGridlines()); dest.setDisplayRowColHeadings(src.isDisplayRowColHeadings()); dest.setGridsPrinted(src.isGridsPrinted()); dest.setPrintGridlines(src.isPrintGridlines()); for (int i = 0; i < src.getNumMergedRegions(); i++) { CellRangeAddress r = src.getMergedRegion(i); dest.addMergedRegion(r); } if (src.getRowBreaks() != null) { for (int row : src.getRowBreaks()) { dest.setRowBreak(row); } } dest.setRowSumsBelow(src.getRowSumsBelow()); dest.setRowSumsRight(src.getRowSumsRight()); int maxcol = 0; for (int i = 0; i <= src.getLastRowNum(); i++) { HSSFRow row = src.getRow(i); if (row != null) { if (maxcol < row.getLastCellNum()) maxcol = row.getLastCellNum(); } } for (int col = 0; col <= maxcol; col++) { if (src.getColumnWidth(col) != src.getDefaultColumnWidth()) dest.setColumnWidth(col, src.getColumnWidth(col)); dest.setColumnHidden(col, src.isColumnHidden(col)); } }