List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle
CellStyle createCellStyle();
From source file:FormatConvert.tab2excel.java
public void tab2excel() throws FileNotFoundException, IOException { Workbook wb = new XSSFWorkbook(); Sheet sheet1 = wb.createSheet("input"); CellStyle style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); int rowIndex = 0; BufferedReader br = null;/*from w ww .j a v a 2 s . co m*/ try { br = new BufferedReader(new FileReader(new File(input))); String[] str; while (br.ready()) { str = br.readLine().split(seperator); Row row = sheet1.createRow(rowIndex); for (int i = 0; i < str.length; i++) { row.createCell(i).setCellValue(str[i]); } rowIndex++; } br.close(); } catch (FileNotFoundException ex) { System.out.println(input + " is not found! please check your filepath "); } catch (IOException ex) { System.out.println("IO error"); } FileOutputStream fileOut = new FileOutputStream(output + ".xlsx"); wb.write(fileOut); fileOut.close(); System.out.println("Convert finished. The output file is named as " + output + ".xlsx"); }
From source file:FormatStatics.BorderedStyle.java
/** * This method alters the workbook object to create a completely bordered * cell for use in tables.//from w w w . j a va2s .com * @param wb The current workbook object that will use the bordered style * @return A bordered cell style. */ public static CellStyle createBorderedStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); return style; }
From source file:forseti.JRepCellStyles.java
License:Open Source License
public JRepCellStyles(Workbook wb) { fenc = wb.createFont();/* ww w . j av a 2 s . co m*/ fenc.setBoldweight(Font.BOLDWEIGHT_BOLD); fenc.setColor(HSSFColor.WHITE.index); fnorm = wb.createFont(); fnorm.setColor(HSSFColor.BLACK.index); csEncCenMEnc = wb.createCellStyle(); csEncRigMEnc = wb.createCellStyle(); csEncLefMEnc = wb.createCellStyle(); csEncCenMAgr = wb.createCellStyle(); csEncRigMAgr = wb.createCellStyle(); csEncLefMAgr = wb.createCellStyle(); csEncCenMNor = wb.createCellStyle(); csEncRigMNor = wb.createCellStyle(); csEncLefMNor = wb.createCellStyle(); csNorCenMEnc = wb.createCellStyle(); csNorRigMEnc = wb.createCellStyle(); csNorLefMEnc = wb.createCellStyle(); csNorCenMAgr = wb.createCellStyle(); csNorRigMAgr = wb.createCellStyle(); csNorLefMAgr = wb.createCellStyle(); csNorCenMNor = wb.createCellStyle(); csNorRigMNor = wb.createCellStyle(); csNorLefMNor = wb.createCellStyle(); csEncCenMEnc.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncCenMEnc.setFont(fenc); csEncRigMEnc.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncRigMEnc.setFont(fenc); csEncLefMEnc.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncLefMEnc.setFont(fenc); csEncCenMAgr.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncCenMAgr.setFont(fenc); csEncRigMAgr.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncRigMAgr.setFont(fenc); csEncLefMAgr.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncLefMAgr.setFont(fenc); csEncCenMNor.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncCenMNor.setFont(fenc); csEncRigMNor.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncRigMNor.setFont(fenc); csEncLefMNor.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csEncLefMNor.setFont(fenc); csNorCenMEnc.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorCenMEnc.setFont(fnorm); csNorRigMEnc.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorRigMEnc.setFont(fnorm); csNorLefMEnc.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorLefMEnc.setFont(fnorm); csNorCenMAgr.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorCenMAgr.setFont(fnorm); csNorRigMAgr.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorRigMAgr.setFont(fnorm); csNorLefMAgr.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorLefMAgr.setFont(fnorm); csNorCenMNor.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorCenMNor.setFont(fnorm); csNorRigMNor.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorRigMNor.setFont(fnorm); csNorLefMNor.setVerticalAlignment(CellStyle.VERTICAL_CENTER); csNorLefMNor.setFont(fnorm); csEncCenMEnc.setAlignment(CellStyle.ALIGN_CENTER); csEncRigMEnc.setAlignment(CellStyle.ALIGN_RIGHT); csEncLefMEnc.setAlignment(CellStyle.ALIGN_LEFT); csEncCenMAgr.setAlignment(CellStyle.ALIGN_CENTER); csEncRigMAgr.setAlignment(CellStyle.ALIGN_RIGHT); csEncLefMAgr.setAlignment(CellStyle.ALIGN_LEFT); csEncCenMNor.setAlignment(CellStyle.ALIGN_CENTER); csEncRigMNor.setAlignment(CellStyle.ALIGN_RIGHT); csEncLefMNor.setAlignment(CellStyle.ALIGN_LEFT); csNorCenMEnc.setAlignment(CellStyle.ALIGN_CENTER); csNorRigMEnc.setAlignment(CellStyle.ALIGN_RIGHT); csNorLefMEnc.setAlignment(CellStyle.ALIGN_LEFT); csNorCenMAgr.setAlignment(CellStyle.ALIGN_CENTER); csNorRigMAgr.setAlignment(CellStyle.ALIGN_RIGHT); csNorLefMAgr.setAlignment(CellStyle.ALIGN_LEFT); csNorCenMNor.setAlignment(CellStyle.ALIGN_CENTER); csNorRigMNor.setAlignment(CellStyle.ALIGN_RIGHT); csNorLefMNor.setAlignment(CellStyle.ALIGN_LEFT); csEncCenMEnc.setBorderTop(CellStyle.BORDER_THIN); csEncCenMEnc.setBorderBottom(CellStyle.BORDER_THIN); csEncCenMEnc.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csEncCenMEnc.setFillPattern(CellStyle.BIG_SPOTS); csEncRigMEnc.setBorderTop(CellStyle.BORDER_THIN); csEncRigMEnc.setBorderBottom(CellStyle.BORDER_THIN); csEncRigMEnc.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csEncRigMEnc.setFillPattern(CellStyle.BIG_SPOTS); csEncLefMEnc.setBorderTop(CellStyle.BORDER_THIN); csEncLefMEnc.setBorderBottom(CellStyle.BORDER_THIN); csEncLefMEnc.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csEncLefMEnc.setFillPattern(CellStyle.BIG_SPOTS); csEncCenMAgr = wb.createCellStyle(); csEncCenMAgr.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csEncCenMAgr.setFillPattern(CellStyle.BIG_SPOTS); csEncRigMAgr = wb.createCellStyle(); csEncRigMAgr.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csEncRigMAgr.setFillPattern(CellStyle.BIG_SPOTS); csEncLefMAgr = wb.createCellStyle(); csEncLefMAgr.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csEncLefMAgr.setFillPattern(CellStyle.BIG_SPOTS); csNorCenMEnc.setBorderTop(CellStyle.BORDER_THIN); csNorCenMEnc.setBorderBottom(CellStyle.BORDER_THIN); csNorCenMEnc.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csNorCenMEnc.setFillPattern(CellStyle.BIG_SPOTS); csNorRigMEnc = wb.createCellStyle(); csNorRigMEnc.setBorderTop(CellStyle.BORDER_THIN); csNorRigMEnc.setBorderBottom(CellStyle.BORDER_THIN); csNorRigMEnc.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csNorRigMEnc.setFillPattern(CellStyle.BIG_SPOTS); csNorLefMEnc.setBorderTop(CellStyle.BORDER_THIN); csNorLefMEnc.setBorderBottom(CellStyle.BORDER_THIN); csNorLefMEnc.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csNorLefMEnc.setFillPattern(CellStyle.BIG_SPOTS); csNorCenMAgr = wb.createCellStyle(); csNorCenMAgr.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csNorCenMAgr.setFillPattern(CellStyle.BIG_SPOTS); csNorRigMAgr = wb.createCellStyle(); csNorRigMAgr.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csNorRigMAgr.setFillPattern(CellStyle.BIG_SPOTS); csNorLefMAgr = wb.createCellStyle(); csNorLefMAgr.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); csNorLefMAgr.setFillPattern(CellStyle.BIG_SPOTS); }
From source file:forseti.reportes.JReportesDlg.java
License:Open Source License
public void generarArchivoXLS(HttpServletRequest request, HttpServletResponse response, Workbook wb) throws ServletException, IOException { JReportesSet m_RepSet = (JReportesSet) request.getAttribute("m_RepSet"); JReportesLevel1 m_setL1 = (JReportesLevel1) request.getAttribute("m_setL1"); JReportesCompL1Set m_setCL1 = (JReportesCompL1Set) request.getAttribute("m_setCL1"); Boolean m_bSelectL1 = (Boolean) request.getAttribute("m_bSelectL1"); Boolean m_bSelectL2 = (Boolean) request.getAttribute("m_bSelectL2"); Boolean m_bSelectL3 = (Boolean) request.getAttribute("m_bSelectL3"); Boolean m_bComputeL1 = (Boolean) request.getAttribute("m_bComputeL1"); Boolean m_bComputeL2 = (Boolean) request.getAttribute("m_bComputeL2"); Boolean m_bComputeL3 = (Boolean) request.getAttribute("m_bComputeL3"); JReportesBind3Set m_colL1 = (JReportesBind3Set) request.getAttribute("m_colL1"); JReportesBind3Set m_colL2 = (JReportesBind3Set) request.getAttribute("m_colL2"); JReportesBind3Set m_colL3 = (JReportesBind3Set) request.getAttribute("m_colL3"); JReportesBind3Set m_colCL1 = (JReportesBind3Set) request.getAttribute("m_colCL1"); JReportesBind3Set m_colCL2 = (JReportesBind3Set) request.getAttribute("m_colCL2"); JReportesBind3Set m_colCL3 = (JReportesBind3Set) request.getAttribute("m_colCL3"); String fsi_filtro = (String) request.getAttribute("fsi_filtro"); Sheet sheet = wb.createSheet("reporte " + Integer.toString(m_RepSet.getAbsRow(0).getID_Report())); short nrow = 0; Row row = sheet.createRow(nrow++);/* w w w. ja v a 2 s .c om*/ Font font = wb.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.DARK_BLUE.index); Cell cell = row.createCell(0); cell.setCellValue(m_RepSet.getAbsRow(0).getDescription() + " " + fsi_filtro); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); cellStyle.setFont(font); cell.setCellStyle(cellStyle); JRepCellStyles cellStyles = new JRepCellStyles(wb); /* Font fenc = wb.createFont(); fenc.setBoldweight(Font.BOLDWEIGHT_BOLD); fenc.setColor(HSSFColor.WHITE.index); Font fnorm = wb.createFont(); fnorm.setColor(HSSFColor.BLACK.index); /////////////////////////////////////////////////////////////////////////////////////////////////////// CellStyle cellStyle = wb.createCellStyle(); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyle.setFont(font); if(alin != null) { if(alin.equals("center")) cellStyle.setAlignment(CellStyle.ALIGN_CENTER); else if(alin.equals("right")) cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); else cellStyle.setAlignment(CellStyle.ALIGN_LEFT); } if(tipocel != null) { if(tipocel.equals("encabezado")) { cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cellStyle.setFillPattern(CellStyle.BIG_SPOTS); } else if(tipocel.equals("agregado")) { cellStyle.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cellStyle.setFillPattern(CellStyle.BIG_SPOTS); } } /////////////////////////////////////////////////////////////////////////////////////////////////////// */ if (m_bSelectL1.booleanValue()) { Row rowl = sheet.createRow(nrow++); for (int i = 0; i < m_colL1.getNumRows(); i++) { if (m_colL1.getAbsRow(i).getWillShow()) { JUtil.DatoXLS(cellStyles, rowl, i, m_colL1.getAbsRow(i).getColName().toUpperCase(), "general", "STRING", m_colL1.getAbsRow(i).getAlinHor(), "encabezado", "fenc", request); //celll1.getCellStyle().setBorderTop(CellStyle.BORDER_THIN); //celll1.getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); } } } if (m_bSelectL2.booleanValue()) { Row rowl = sheet.createRow(nrow++); for (int i = 0; i < m_colL2.getNumRows(); i++) { if (m_colL2.getAbsRow(i).getWillShow()) { JUtil.DatoXLS(cellStyles, rowl, i, m_colL2.getAbsRow(i).getColName().toUpperCase(), "general", "STRING", m_colL2.getAbsRow(i).getAlinHor(), "encabezado", "fenc", request); //celll2.getCellStyle().setBorderTop(CellStyle.BORDER_THIN); //celll2.getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); } } } if (m_bSelectL3.booleanValue()) { Row rowl = sheet.createRow(nrow++); for (int i = 0; i < m_colL3.getNumRows(); i++) { if (m_colL3.getAbsRow(i).getWillShow()) { JUtil.DatoXLS(cellStyles, rowl, i, m_colL3.getAbsRow(i).getColName().toUpperCase(), "general", "STRING", m_colL3.getAbsRow(i).getAlinHor(), "encabezado", "fenc", request); //celll3.getCellStyle().setBorderTop(CellStyle.BORDER_THIN); //celll3.getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); } } } if (m_bSelectL1.booleanValue()) { for (int RL1 = 0; RL1 < m_setL1.getNumRows(); RL1++) { Row rowl1 = sheet.createRow(nrow++); for (int CL1 = 0; CL1 < m_colL1.getNumRows(); CL1++) { if (m_colL1.getAbsRow(CL1).getWillShow()) JUtil.DatoXLS(cellStyles, rowl1, CL1, m_setL1.getAbsRow(RL1).getSTS(m_colL1.getAbsRow(CL1).getColName()), m_colL1.getAbsRow(CL1).getFormat(), m_colL1.getAbsRow(CL1).getBindDataType(), m_colL1.getAbsRow(CL1).getAlinHor(), null, "fnorm", request); } // Nivel 2 if (m_bSelectL2.booleanValue()) { for (int RL2 = 0; RL2 < m_setL1.getAbsRow(RL1).getSetL2().getNumRows(); RL2++) { Row rowl2 = sheet.createRow(nrow++); for (int CL2 = 0; CL2 < m_colL2.getNumRows(); CL2++) { if (m_colL2.getAbsRow(CL2).getWillShow()) JUtil.DatoXLS(cellStyles, rowl2, CL2, m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2) .getSTS(m_colL2.getAbsRow(CL2).getColName()), m_colL2.getAbsRow(CL2).getFormat(), m_colL2.getAbsRow(CL2).getBindDataType(), m_colL2.getAbsRow(CL2).getAlinHor(), null, "fnorm", request); } // Nivel 3 if (m_bSelectL3.booleanValue()) { for (int RL3 = 0; RL3 < m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetL3() .getNumRows(); RL3++) { Row rowl3 = sheet.createRow(nrow++); for (int CL3 = 0; CL3 < m_colL3.getNumRows(); CL3++) { if (m_colL3.getAbsRow(CL3).getWillShow()) JUtil.DatoXLS(cellStyles, rowl3, CL3, m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetL3() .getAbsRow(RL3).getSTS(m_colL3.getAbsRow(CL3).getColName()), m_colL3.getAbsRow(CL3).getFormat(), m_colL3.getAbsRow(CL3).getBindDataType(), m_colL3.getAbsRow(CL3).getAlinHor(), null, "fnorm", request); } } if (m_bComputeL3.booleanValue()) { for (int RC3 = 0; RC3 < m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetCL3() .getNumRows(); RC3++) { Row rowc3 = sheet.createRow(nrow++); for (int CC3 = 0; CC3 < m_colCL3.getNumRows(); CC3++) { if (m_colCL3.getAbsRow(CC3).getWillShow()) JUtil.DatoXLS(cellStyles, rowc3, CC3, m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetCL3() .getAbsRow(RC3) .getSTS(m_colCL3.getAbsRow(CC3).getColName()), m_colCL3.getAbsRow(CC3).getFormat(), m_colCL3.getAbsRow(CC3).getBindDataType(), m_colCL3.getAbsRow(CC3).getAlinHor(), "agregado", "fenc", request); } } } // Fin SI CL3 } // Fin SI L3 } if (m_bComputeL2.booleanValue()) { for (int RC2 = 0; RC2 < m_setL1.getAbsRow(RL1).getSetCL2().getNumRows(); RC2++) { Row rowc2 = sheet.createRow(nrow++); for (int CC2 = 0; CC2 < m_colCL2.getNumRows(); CC2++) { if (m_colCL2.getAbsRow(CC2).getWillShow()) JUtil.DatoXLS(cellStyles, rowc2, CC2, m_setL1.getAbsRow(RL1).getSetCL2().getAbsRow(RC2) .getSTS(m_colCL2.getAbsRow(CC2).getColName()), m_colCL2.getAbsRow(CC2).getFormat(), m_colCL2.getAbsRow(CC2).getBindDataType(), m_colCL2.getAbsRow(CC2).getAlinHor(), "agregado", "fenc", request); } } } // Fin SI CL2 } // Fin SI L2 } if (m_bComputeL1.booleanValue()) { for (int RC1 = 0; RC1 < m_setCL1.getNumRows(); RC1++) { Row rowc1 = sheet.createRow(nrow++); for (int CC1 = 0; CC1 < m_colCL1.getNumRows(); CC1++) { if (m_colCL1.getAbsRow(CC1).getWillShow()) JUtil.DatoXLS(cellStyles, rowc1, CC1, m_setCL1.getAbsRow(RC1).getSTS(m_colCL1.getAbsRow(CC1).getColName()), m_colCL1.getAbsRow(CC1).getFormat(), m_colCL1.getAbsRow(CC1).getBindDataType(), m_colCL1.getAbsRow(CC1).getAlinHor(), "agregado", "fenc", request); } } } // Fin SI CL1 } // Fin SI L1 int colsmer; if (m_colL1.getNumRows() > m_colL2.getNumRows() && m_colL1.getNumRows() > m_colL3.getNumRows()) colsmer = m_colL1.getNumRows() - 1; else if (m_colL2.getNumRows() > m_colL1.getNumRows() && m_colL2.getNumRows() > m_colL3.getNumRows()) colsmer = m_colL2.getNumRows() - 1; else colsmer = m_colL3.getNumRows() - 1; sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, (colsmer == -1 ? 0 : colsmer))); }
From source file:fsi_admin.reportes.JReportesDlg.java
License:Open Source License
public void generarArchivoXLS(HttpServletRequest request, HttpServletResponse response, Workbook wb) throws ServletException, IOException { JReportesSet m_RepSet = (JReportesSet) request.getAttribute("m_RepSet"); JReportesLevel1 m_setL1 = (JReportesLevel1) request.getAttribute("m_setL1"); JReportesCompL1Set m_setCL1 = (JReportesCompL1Set) request.getAttribute("m_setCL1"); Boolean m_bSelectL1 = (Boolean) request.getAttribute("m_bSelectL1"); Boolean m_bSelectL2 = (Boolean) request.getAttribute("m_bSelectL2"); Boolean m_bSelectL3 = (Boolean) request.getAttribute("m_bSelectL3"); Boolean m_bComputeL1 = (Boolean) request.getAttribute("m_bComputeL1"); Boolean m_bComputeL2 = (Boolean) request.getAttribute("m_bComputeL2"); Boolean m_bComputeL3 = (Boolean) request.getAttribute("m_bComputeL3"); JReportesBind3Set m_colL1 = (JReportesBind3Set) request.getAttribute("m_colL1"); JReportesBind3Set m_colL2 = (JReportesBind3Set) request.getAttribute("m_colL2"); JReportesBind3Set m_colL3 = (JReportesBind3Set) request.getAttribute("m_colL3"); JReportesBind3Set m_colCL1 = (JReportesBind3Set) request.getAttribute("m_colCL1"); JReportesBind3Set m_colCL2 = (JReportesBind3Set) request.getAttribute("m_colCL2"); JReportesBind3Set m_colCL3 = (JReportesBind3Set) request.getAttribute("m_colCL3"); String fsi_filtro = (String) request.getAttribute("fsi_filtro"); Sheet sheet = wb.createSheet("reporte " + Integer.toString(m_RepSet.getAbsRow(0).getID_Report())); short nrow = 0; Row row = sheet.createRow(nrow++);/* ww w . j a va 2s . c o m*/ Font font = wb.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.DARK_BLUE.index); Cell cell = row.createCell(0); cell.setCellValue(m_RepSet.getAbsRow(0).getDescription() + " " + fsi_filtro); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); cellStyle.setFont(font); cell.setCellStyle(cellStyle); JRepCellStyles cellStyles = new JRepCellStyles(wb); if (m_bSelectL1.booleanValue()) { Row rowl = sheet.createRow(nrow++); for (int i = 0; i < m_colL1.getNumRows(); i++) { if (m_colL1.getAbsRow(i).getWillShow()) { JUtil.DatoXLS(cellStyles, rowl, i, m_colL1.getAbsRow(i).getColName(), "general", "STRING", m_colL1.getAbsRow(i).getAlinHor(), "encabezado", "fenc", request); //celll1.getCellStyle().setBorderTop(CellStyle.BORDER_THIN); //celll1.getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); } } } if (m_bSelectL2.booleanValue()) { Row rowl = sheet.createRow(nrow++); for (int i = 0; i < m_colL2.getNumRows(); i++) { if (m_colL2.getAbsRow(i).getWillShow()) { JUtil.DatoXLS(cellStyles, rowl, i, m_colL2.getAbsRow(i).getColName(), "general", "STRING", m_colL2.getAbsRow(i).getAlinHor(), "encabezado", "fenc", request); //celll2.getCellStyle().setBorderTop(CellStyle.BORDER_THIN); //celll2.getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); } } } if (m_bSelectL3.booleanValue()) { Row rowl = sheet.createRow(nrow++); for (int i = 0; i < m_colL3.getNumRows(); i++) { if (m_colL3.getAbsRow(i).getWillShow()) { JUtil.DatoXLS(cellStyles, rowl, i, m_colL3.getAbsRow(i).getColName(), "general", "STRING", m_colL3.getAbsRow(i).getAlinHor(), "encabezado", "fenc", request); //celll3.getCellStyle().setBorderTop(CellStyle.BORDER_THIN); //celll3.getCellStyle().setBorderBottom(CellStyle.BORDER_THIN); } } } if (m_bSelectL1.booleanValue()) { for (int RL1 = 0; RL1 < m_setL1.getNumRows(); RL1++) { Row rowl1 = sheet.createRow(nrow++); for (int CL1 = 0; CL1 < m_colL1.getNumRows(); CL1++) { if (m_colL1.getAbsRow(CL1).getWillShow()) JUtil.DatoXLS(cellStyles, rowl1, CL1, m_setL1.getAbsRow(RL1).getSTS(m_colL1.getAbsRow(CL1).getColName()), m_colL1.getAbsRow(CL1).getFormat(), m_colL1.getAbsRow(CL1).getBindDataType(), m_colL1.getAbsRow(CL1).getAlinHor(), null, "fnorm", request); } // Nivel 2 if (m_bSelectL2.booleanValue()) { for (int RL2 = 0; RL2 < m_setL1.getAbsRow(RL1).getSetL2().getNumRows(); RL2++) { Row rowl2 = sheet.createRow(nrow++); for (int CL2 = 0; CL2 < m_colL2.getNumRows(); CL2++) { if (m_colL2.getAbsRow(CL2).getWillShow()) JUtil.DatoXLS(cellStyles, rowl2, CL2, m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2) .getSTS(m_colL2.getAbsRow(CL2).getColName()), m_colL2.getAbsRow(CL2).getFormat(), m_colL2.getAbsRow(CL2).getBindDataType(), m_colL2.getAbsRow(CL2).getAlinHor(), null, "fnorm", request); } // Nivel 3 if (m_bSelectL3.booleanValue()) { for (int RL3 = 0; RL3 < m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetL3() .getNumRows(); RL3++) { Row rowl3 = sheet.createRow(nrow++); for (int CL3 = 0; CL3 < m_colL3.getNumRows(); CL3++) { if (m_colL3.getAbsRow(CL3).getWillShow()) JUtil.DatoXLS(cellStyles, rowl3, CL3, m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetL3() .getAbsRow(RL3).getSTS(m_colL3.getAbsRow(CL3).getColName()), m_colL3.getAbsRow(CL3).getFormat(), m_colL3.getAbsRow(CL3).getBindDataType(), m_colL3.getAbsRow(CL3).getAlinHor(), null, "fnorm", request); } } if (m_bComputeL3.booleanValue()) { for (int RC3 = 0; RC3 < m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetCL3() .getNumRows(); RC3++) { Row rowc3 = sheet.createRow(nrow++); for (int CC3 = 0; CC3 < m_colCL3.getNumRows(); CC3++) { if (m_colCL3.getAbsRow(CC3).getWillShow()) JUtil.DatoXLS(cellStyles, rowc3, CC3, m_setL1.getAbsRow(RL1).getSetL2().getAbsRow(RL2).getSetCL3() .getAbsRow(RC3) .getSTS(m_colCL3.getAbsRow(CC3).getColName()), m_colCL3.getAbsRow(CC3).getFormat(), m_colCL3.getAbsRow(CC3).getBindDataType(), m_colCL3.getAbsRow(CC3).getAlinHor(), "agregado", "fenc", request); } } } // Fin SI CL3 } // Fin SI L3 } if (m_bComputeL2.booleanValue()) { for (int RC2 = 0; RC2 < m_setL1.getAbsRow(RL1).getSetCL2().getNumRows(); RC2++) { Row rowc2 = sheet.createRow(nrow++); for (int CC2 = 0; CC2 < m_colCL2.getNumRows(); CC2++) { if (m_colCL2.getAbsRow(CC2).getWillShow()) JUtil.DatoXLS(cellStyles, rowc2, CC2, m_setL1.getAbsRow(RL1).getSetCL2().getAbsRow(RC2) .getSTS(m_colCL2.getAbsRow(CC2).getColName()), m_colCL2.getAbsRow(CC2).getFormat(), m_colCL2.getAbsRow(CC2).getBindDataType(), m_colCL2.getAbsRow(CC2).getAlinHor(), "agregado", "fenc", request); } } } // Fin SI CL2 } // Fin SI L2 } if (m_bComputeL1.booleanValue()) { for (int RC1 = 0; RC1 < m_setCL1.getNumRows(); RC1++) { Row rowc1 = sheet.createRow(nrow++); for (int CC1 = 0; CC1 < m_colCL1.getNumRows(); CC1++) { if (m_colCL1.getAbsRow(CC1).getWillShow()) JUtil.DatoXLS(cellStyles, rowc1, CC1, m_setCL1.getAbsRow(RC1).getSTS(m_colCL1.getAbsRow(CC1).getColName()), m_colCL1.getAbsRow(CC1).getFormat(), m_colCL1.getAbsRow(CC1).getBindDataType(), m_colCL1.getAbsRow(CC1).getAlinHor(), "agregado", "fenc", request); } } } // Fin SI CL1 } // Fin SI L1 int colsmer; if (m_colL1.getNumRows() > m_colL2.getNumRows() && m_colL1.getNumRows() > m_colL3.getNumRows()) colsmer = m_colL1.getNumRows() - 1; else if (m_colL2.getNumRows() > m_colL1.getNumRows() && m_colL2.getNumRows() > m_colL3.getNumRows()) colsmer = m_colL2.getNumRows() - 1; else colsmer = m_colL3.getNumRows() - 1; sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, (colsmer == -1 ? 0 : colsmer))); }
From source file:gov.nasa.ensemble.core.plan.editor.merge.export.ExcelExportWizard.java
License:Open Source License
@Override protected void savePlan(EPlan plan, File destinationFilename) throws Exception { boolean generatingResourceSummaryTable = isGeneratingResourceSummaryTable(); boolean generatingPlanTable = isGeneratingActivityTable(); Workbook wb = new HSSFWorkbook(); Sheet planSheet = generatingPlanTable ? wb.createSheet("Plan") : null; Sheet resourceSheet = generatingResourceSummaryTable ? wb.createSheet("Resource Statistics") : null; CellStyle headerStyle = wb.createCellStyle(); Font font = wb.createFont();/*from www . j a va 2 s . c o m*/ font.setBoldweight(Font.BOLDWEIGHT_BOLD); headerStyle.setFont(font); if (generatingPlanTable && planSheet != null) { List<String> attributeNames = getActivityColumnHeaders(); writeRow(planSheet.createRow(0), trimColumnHeaders(attributeNames), headerStyle); int rowNum = 1; List<RowForOneActivity> allActivitiesColumns = getColumnsForActivitiesToExport(plan, attributeNames); for (RowForOneActivity activityColumns : allActivitiesColumns) { writeRow(planSheet.createRow(rowNum++), activityColumns.allColumnsAsFormatted, null); } } if (generatingResourceSummaryTable && resourceSheet != null) { writeRow(resourceSheet.createRow(0), new String[] { getDescription(plan) }, headerStyle); Statistic[] statistics = getResourceColumnHeaders(); writeRow(resourceSheet.createRow(1), mapToStrings(statistics), headerStyle); int rowNum = 2; List<String[]> resourcesColumns = getColumnsForResourceStats(plan, statistics); for (String[] resourceColumns : resourcesColumns) { writeRow(resourceSheet.createRow(rowNum++), resourceColumns, null); } } try { FileOutputStream out = new FileOutputStream(destinationFilename); wb.write(out); out.close(); } catch (IllegalArgumentException iae) { iae.printStackTrace(); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:gov.nih.nci.cadsr.cdecurate.test.TestSpreadsheetDownload.java
License:BSD License
private void createDownloadColumns(ArrayList<String[]> allRows) { final int MAX_ROWS = 65000; String sheetName = "Custom Download"; int sheetNum = 1; String fillIn = "false";// set true to fill in all values. String[] columns = null;/*w w w . j av a 2 s . com*/ ArrayList<String> defaultHeaders = new ArrayList<String>(); for (String cName : allExpandedColumnHeaders) { if (cName.endsWith("IDSEQ") || cName.startsWith("CD ") || cName.startsWith("Conceptual Domain")) { /* skip */ } else { System.out.println("cName = " + cName); defaultHeaders.add(cName); } } columns = defaultHeaders.toArray(new String[defaultHeaders.size()]); int[] colIndices = new int[columns.length]; for (int i = 0; i < columns.length; i++) { String colName = columns[i]; if (columnHeaders.indexOf(colName) < 0) { String tempType = arrayColumnTypes.get(colName); int temp = columnTypes.indexOf(tempType); colIndices[i] = temp; } else { int temp = columnHeaders.indexOf(colName); colIndices[i] = temp; } } Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(sheetName); Font font = wb.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle boldCellStyle = wb.createCellStyle(); boldCellStyle.setFont(font); boldCellStyle.setAlignment(CellStyle.ALIGN_GENERAL); Row headerRow = sheet.createRow(0); headerRow.setHeightInPoints(12.75f); String temp; for (int i = 0; i < columns.length; i++) { Cell cell = headerRow.createCell(i); temp = columns[i]; cell.setCellValue(temp); cell.setCellStyle(boldCellStyle); } // freeze the first row sheet.createFreezePane(0, 1); Row row = null; Cell cell; int rownum = 1; int bump = 0; int i = 0; try { System.out.println("Total CDEs to download [" + allRows.size() + "]"); for (i = 0; i < allRows.size(); i++, rownum++) { // Check if row already exists int maxBump = 0; if (sheet.getRow(rownum + bump) == null) { row = sheet.createRow(rownum + bump); } if (allRows.get(i) == null) continue; for (int j = 0; j < colIndices.length; j++) { cell = row.createCell(j); String currentType = columnTypes.get(colIndices[j]); if (currentType.endsWith("_T")) { // Deal with CS/CSI String[] originalArrColNames = typeMap.get(currentType).get(0); // Find current column in original data int originalColumnIndex = -1; for (int a = 0; a < originalArrColNames.length; a++) { if (columns[j].equals(originalArrColNames[a])) { originalColumnIndex = a; break; } } // ArrayList<HashMap<String,ArrayList<String[]>>> // arrayData1 = // (ArrayList<HashMap<String,ArrayList<String[]>>>)arrayData; HashMap<String, List<String[]>> typeArrayData = arrayData.get(i); ArrayList<String[]> rowArrayData = (ArrayList<String[]>) typeArrayData.get(currentType); if (rowArrayData != null) { int tempBump = 0; for (int nestedRowIndex = 0; nestedRowIndex < rowArrayData.size(); nestedRowIndex++) { String[] nestedData = rowArrayData.get(nestedRowIndex); String data = ""; if (currentType.contains("DERIVED")) { // Derived data element is special double // nested, needs to be modified to be more // general. // General DDE information is in the first 4 // columns, but contained in the first row // of the Row Array Data if (originalColumnIndex < 5) { if (nestedRowIndex == 0) data = (originalColumnIndex > 0) ? nestedData[originalColumnIndex] : nestedData[originalColumnIndex + 1]; } else { if (nestedRowIndex + 1 < rowArrayData.size()) { data = rowArrayData.get(nestedRowIndex + 1)[originalColumnIndex - 5]; } } } else data = nestedData[originalColumnIndex]; logger.debug( "at line 828 of TestSpreadsheetDownload.java*****" + data + currentType); if (currentType.contains("VALID_VALUE")) { data = AdministeredItemUtil.truncateTime(data); } cell.setCellValue(data); tempBump++; if (nestedRowIndex < rowArrayData.size() - 1) { row = sheet.getRow(rownum + bump + tempBump); if (row == null) { if (rownum + bump + tempBump >= MAX_ROWS) { sheet = wb.createSheet(sheetName + "_" + sheetNum); sheetNum++; rownum = 1; bump = 0; tempBump = 0; } row = sheet.createRow(rownum + bump + tempBump); } cell = row.createCell(j); } else { // Go back to top row row = sheet.getRow(rownum + bump); if (tempBump > maxBump) maxBump = tempBump; } } } } else { temp = allRows.get(i)[colIndices[j]]; logger.debug("at line 866 of TestSpreadsheetDownload.java*****" + temp + currentType); if (currentType.equalsIgnoreCase("Date")) { temp = AdministeredItemUtil.truncateTime(temp); } cell.setCellValue(temp); } } bump = bump + maxBump; if (fillIn != null && (fillIn.equals("true") || fillIn.equals("yes") && bump > 0)) { sheet = fillInBump(sheet, i, rownum, bump, allRows, columnTypes, colIndices); rownum = rownum + bump; bump = 0; } } } catch (Exception e) { e.printStackTrace(); } try { // Please specify the path below if needed, otherwise it will create in the root/dir where this test class is run fileOutputStream = new FileOutputStream("Test_Excel.xls"); wb.write(fileOutputStream); } catch (Exception e) { e.printStackTrace(); } finally { /** * Close the fileOutputStream. */ try { if (fileOutputStream != null) { fileOutputStream.close(); } } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:gov.nih.nci.cadsr.cdecurate.tool.CustomDownloadServlet.java
License:BSD License
private void createDownloadColumns(ArrayList<String[]> allRows) { final int MAX_ROWS = 65000; String sheetName = "Custom Download"; int sheetNum = 1; String colString = (String) this.m_classReq.getParameter("cdlColumns"); String fillIn = (String) this.m_classReq.getParameter("fillIn"); ArrayList<String> allHeaders = (ArrayList<String>) m_classReq.getSession().getAttribute("headers"); ArrayList<String> allExpandedHeaders = (ArrayList<String>) m_classReq.getSession() .getAttribute("allExpandedHeaders"); ArrayList<String> allTypes = (ArrayList<String>) m_classReq.getSession().getAttribute("types"); HashMap<String, ArrayList<String[]>> typeMap = (HashMap<String, ArrayList<String[]>>) m_classReq .getSession().getAttribute("typeMap"); ArrayList<HashMap<String, ArrayList<String[]>>> arrayData = (ArrayList<HashMap<String, ArrayList<String[]>>>) m_classReq .getSession().getAttribute("arrayData"); HashMap<String, String> arrayColumnTypes = (HashMap<String, String>) m_classReq.getSession() .getAttribute("arrayColumnTypes"); String[] columns = null;/*from www . j a v a2s. co m*/ if (colString != null && !colString.trim().equals("")) { columns = colString.split(","); } else { ArrayList<String> defaultHeaders = new ArrayList<String>(); for (String cName : allExpandedHeaders) { if (cName.endsWith("IDSEQ") || cName.startsWith("CD ") || cName.startsWith("Conceptual Domain")) { /*skip*/ } else { System.out.println("cName = " + cName); defaultHeaders.add(cName); } } columns = defaultHeaders.toArray(new String[defaultHeaders.size()]); } int[] colIndices = new int[columns.length]; for (int i = 0; i < columns.length; i++) { String colName = columns[i]; if (allHeaders.indexOf(colName) < 0) { String tempType = arrayColumnTypes.get(colName); int temp = allTypes.indexOf(tempType); colIndices[i] = temp; } else { int temp = allHeaders.indexOf(colName); colIndices[i] = temp; } } Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(sheetName); Font font = wb.createFont(); //GF30779 font.setBoldweight(Font.BOLDWEIGHT_BOLD); //GF30779 CellStyle boldCellStyle = wb.createCellStyle(); //GF30779 boldCellStyle.setFont(font); //GF30779 boldCellStyle.setAlignment(CellStyle.ALIGN_GENERAL); //GF30779 Row headerRow = sheet.createRow(0); headerRow.setHeightInPoints(12.75f); String temp; for (int i = 0; i < columns.length; i++) { Cell cell = headerRow.createCell(i); temp = columns[i]; cell.setCellValue(temp); cell.setCellStyle(boldCellStyle); //GF30779 } //freeze the first row sheet.createFreezePane(0, 1); Row row = null; Cell cell; int rownum = 1; int bump = 0; boolean fillRow = false; int i = 0; long startTime = System.currentTimeMillis(); try { System.out.println("Total CDEs to download [" + allRows.size() + "]"); for (i = 0; i < allRows.size(); i++, rownum++) { //Check if row already exists int maxBump = 0; if (sheet.getRow(rownum + bump) == null) { row = sheet.createRow(rownum + bump); } if (allRows.get(i) == null) continue; for (int j = 0; j < colIndices.length; j++) { cell = row.createCell(j); String currentType = allTypes.get(colIndices[j]); if (currentType.endsWith("_T")) { //Deal with CS/CSI String[] originalArrColNames = typeMap.get(currentType).get(0); //Find current column in original data int originalColumnIndex = -1; for (int a = 0; a < originalArrColNames.length; a++) { if (columns[j].equals(originalArrColNames[a])) { originalColumnIndex = a; break; } } HashMap<String, ArrayList<String[]>> typeArrayData = arrayData.get(i); ArrayList<String[]> rowArrayData = typeArrayData.get(currentType); if (rowArrayData != null) { int tempBump = 0; for (int nestedRowIndex = 0; nestedRowIndex < rowArrayData.size(); nestedRowIndex++) { String[] nestedData = rowArrayData.get(nestedRowIndex); String data = ""; if (currentType.contains("DERIVED")) { //Derived data element is special double nested, needs to be modified to be more general. //General DDE information is in the first 4 columns, but contained in the first row of the Row Array Data if (originalColumnIndex < 5) { if (nestedRowIndex == 0) data = (originalColumnIndex > 0) ? nestedData[originalColumnIndex] : nestedData[originalColumnIndex + 1]; //This skips the 2nd entry, description, which is not to be shown. } else { if (nestedRowIndex + 1 < rowArrayData.size()) { data = rowArrayData.get(nestedRowIndex + 1)[originalColumnIndex - 5]; } } } else data = nestedData[originalColumnIndex]; logger.debug("at line 960 of CustomDownloadServlet.java*****" + data + currentType); if (currentType.contains("VALID_VALUE")) { //GF30779 data = AdministeredItemUtil.truncateTime(data); } cell.setCellValue(data); tempBump++; if (nestedRowIndex < rowArrayData.size() - 1) { row = sheet.getRow(rownum + bump + tempBump); if (row == null) { if (rownum + bump + tempBump >= MAX_ROWS) { sheet = wb.createSheet(sheetName + "_" + sheetNum); sheetNum++; rownum = 1; bump = 0; tempBump = 0; } row = sheet.createRow(rownum + bump + tempBump); } cell = row.createCell(j); } else { //Go back to top row row = sheet.getRow(rownum + bump); if (tempBump > maxBump) maxBump = tempBump; } } } } else { temp = allRows.get(i)[colIndices[j]]; logger.debug("at line 993 of CustomDownloadServlet.java*****" + temp + currentType); if (currentType.equalsIgnoreCase("Date")) { //GF30779 temp = AdministeredItemUtil.truncateTime(temp); } cell.setCellValue(temp); } } bump = bump + maxBump; if (fillIn != null && (fillIn.equals("true") || fillIn.equals("yes") && bump > 0)) { sheet = fillInBump(sheet, i, rownum, bump, allRows, allTypes, colIndices); rownum = rownum + bump; bump = 0; } } } catch (Exception e) { e.printStackTrace(); } // sheet.setZoom(3, 4); //GF30779 // Write the output to response stream. try { m_classRes.setContentType("application/vnd.ms-excel"); m_classRes.setHeader("Content-Disposition", "attachment; filename=\"customDownload.xls\""); OutputStream out = m_classRes.getOutputStream(); wb.write(out); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:guru.qas.martini.report.DefaultState.java
License:Apache License
public void updateLongestExecutions() { if (!longestExecutionCells.isEmpty()) { for (Cell cell : longestExecutionCells) { CellStyle original = cell.getCellStyle(); Sheet sheet = cell.getSheet(); Workbook workbook = sheet.getWorkbook(); CellStyle newStyle = workbook.createCellStyle(); newStyle.cloneStyleFrom(original); int originalFontIndex = original.getFontIndexAsInt(); Font originalFont = workbook.getFontAt(originalFontIndex); Font font = workbook.createFont(); font.setBold(true);//from www. j ava 2s .c o m font.setColor(IndexedColors.DARK_RED.getIndex()); font.setFontHeight((short) Math.round(originalFont.getFontHeight() * 1.5)); newStyle.setFont(font); cell.setCellStyle(newStyle); Row row = cell.getRow(); short firstCellNum = row.getFirstCellNum(); short lastCellNum = row.getLastCellNum(); for (int i = firstCellNum; i < lastCellNum; i++) { Cell rowCell = row.getCell(i); original = rowCell.getCellStyle(); CellStyle borderStyle = workbook.createCellStyle(); borderStyle.cloneStyleFrom(original); borderStyle.setBorderTop(BorderStyle.MEDIUM); borderStyle.setBorderBottom(BorderStyle.MEDIUM); if (i == cell.getColumnIndex()) { borderStyle.setBorderLeft(BorderStyle.MEDIUM); borderStyle.setBorderRight(BorderStyle.MEDIUM); } else if (i == firstCellNum) { borderStyle.setBorderLeft(BorderStyle.MEDIUM); } else if (i == lastCellNum - 1) { borderStyle.setBorderRight(BorderStyle.MEDIUM); } rowCell.setCellStyle(borderStyle); } } } }
From source file:guru.qas.martini.report.DefaultState.java
License:Apache License
protected void colorRow(short color, Row row) { short firstCellNum = row.getFirstCellNum(); short lastCellNum = row.getLastCellNum(); for (int i = firstCellNum; i <= lastCellNum; i++) { Cell cell = row.getCell(i);//from w w w .ja va2 s . c o m if (null != cell) { CellStyle cellStyle = cell.getCellStyle(); Workbook workbook = cell.getSheet().getWorkbook(); CellStyle clone = workbook.createCellStyle(); clone.cloneStyleFrom(cellStyle); clone.setFillForegroundColor(color); clone.setFillPattern(FillPatternType.SOLID_FOREGROUND); BorderStyle borderStyle = cellStyle.getBorderLeftEnum(); clone.setBorderLeft(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle); short borderColor = cellStyle.getLeftBorderColor(); clone.setLeftBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor); borderStyle = cellStyle.getBorderRightEnum(); clone.setBorderRight(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle); borderColor = cellStyle.getRightBorderColor(); clone.setRightBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor); borderStyle = cellStyle.getBorderTopEnum(); clone.setBorderTop(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle); borderColor = cellStyle.getTopBorderColor(); clone.setTopBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor); borderStyle = cellStyle.getBorderBottomEnum(); clone.setBorderBottom(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle); borderColor = cellStyle.getBottomBorderColor(); clone.setBottomBorderColor(borderColor); cell.setCellStyle(clone); } } }