List of usage examples for org.apache.poi.ss.usermodel Workbook createFont
Font createFont();
From source file:FormatStatics.HeaderFormats.java
/** * A generic method for creating a cell style with a gray bold header * @param wb The current workbook object * @return The desired cellstyle format/* w w w . j av a2 s. c o m*/ */ public static CellStyle GreyBoldHeader(Workbook wb) { CellStyle style; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = BorderedStyle.createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); return style; }
From source file:FormatStatics.HeaderFormats.java
/** * A generic method for creating a cell style with a gray header * @param wb The current workbook object * @return The desired cellstyle format/* w w w . j av a 2s . co m*/ */ public static CellStyle GreyHeader(Workbook wb) { CellStyle style; Font headerFont = wb.createFont(); style = BorderedStyle.createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); return style; }
From source file:FormatStatics.HeaderFormats.java
/** * A generic method for creating a cell style with a custom color bold header * @param wb The current workbook object * @param color a lowercase string indicating the color desired * @return The desired cellstyle format// w w w . j a v a2 s . c o m */ public static CellStyle CustomBoldCenterHeader(Workbook wb, String color) { CellStyle style; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = BorderedStyle.createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(InterpretColor(color)); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); return style; }
From source file:FormatStatics.HeaderFormats.java
/** * A generic method for creating a cell style with a custom bold header * @param wb The current workbook object * @param color a short value indicating the color desired; from the Apache * POI short list of colors/*from w w w . j a v a2 s. c o m*/ * @return The desired cellstyle format */ public static CellStyle CustomBoldCenterHeader(Workbook wb, short color) { CellStyle style; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = BorderedStyle.createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(color); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); return style; }
From source file:FormatStatics.HighlightStyle.java
/** * A Highlight style that uses a custom color short value; short values * are derived from the Apache POI color definitions * @param wb The current workbook object * @param color a short value indicating the color desired; from the Apache * POI short list of colors//from w w w.j a va2s . c om * @return The desired cellstyle format */ public static CellStyle CustomBoldHighlight(Workbook wb, Short color) { CellStyle style; Font highlightFont = wb.createFont(); highlightFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = BorderedStyle.createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFillForegroundColor(color); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(highlightFont); return style; }
From source file:FormatStatics.HighlightStyle.java
/** * A simple highlight style that returns a bright yellow highlight cell style * @param wb The current workbook object * @return The desired yellow cell style *///from w ww . j ava 2 s.c o m public static CellStyle YellowBoldHighlight(Workbook wb) { CellStyle style; Font highlightFont = wb.createFont(); highlightFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = BorderedStyle.createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(highlightFont); return style; }
From source file:forseti.JRepCellStyles.java
License:Open Source License
public JRepCellStyles(Workbook wb) { fenc = wb.createFont(); fenc.setBoldweight(Font.BOLDWEIGHT_BOLD); fenc.setColor(HSSFColor.WHITE.index); fnorm = wb.createFont();/*from w ww . j a va2 s . c o m*/ 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. j a v a2 s . 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); /* 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++);/*w w w.j ava 2 s . 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(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); headerStyle.setFont(font);/*from w ww .j ava2s . co m*/ 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(); } }