List of usage examples for org.apache.poi.ss.usermodel Cell setCellValue
void setCellValue(boolean value);
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void tableFacet(FacesContext context, Sheet sheet, DataTable table, int columnCount, String facetType) {//from w w w . ja v a 2 s . c o m Map<String, UIComponent> map = table.getFacets(); UIComponent component = map.get(facetType); if (component != null) { String headerValue = null; if (component instanceof HtmlCommandButton) { headerValue = exportValue(context, component); } else if (component instanceof HtmlCommandLink) { headerValue = exportValue(context, component); } else if (component instanceof UIPanel) { String header = ""; for (UIComponent child : component.getChildren()) { headerValue = exportValue(context, child); header = header + headerValue; } headerValue = header; } else { headerValue = exportFacetValue(context, component); } int sheetRowIndex = sheet.getLastRowNum() + 1; Row row = sheet.createRow(sheetRowIndex); Cell cell = row.createCell((short) 0); cell.setCellValue(headerValue); cell.setCellStyle(facetStyle); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex, //last row (0-based) 0, //first column (0-based) columnCount + 1 //last column (0-based) )); } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void tableFacet(FacesContext context, Sheet sheet, SubTable table, int columnCount, String facetType) {// w w w . ja v a2 s . co m Map<String, UIComponent> map = table.getFacets(); UIComponent component = map.get(facetType); if (component != null) { String headerValue = null; if (component instanceof HtmlCommandButton) { headerValue = exportValue(context, component); } else if (component instanceof HtmlCommandLink) { headerValue = exportValue(context, component); } else if (component instanceof UIPanel) { String header = ""; for (UIComponent child : component.getChildren()) { headerValue = exportValue(context, child); header = header + headerValue; } headerValue = header; } else { headerValue = exportFacetValue(context, component); } int sheetRowIndex = sheet.getLastRowNum() + 1; Row row = sheet.createRow(sheetRowIndex); Cell cell = row.createCell((short) 0); cell.setCellValue(headerValue); cell.setCellStyle(facetStyle); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex, //last row (0-based) 0, //first column (0-based) columnCount //last column (0-based) )); } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void tableFacet(FacesContext context, Sheet sheet, DataList list, String facetType) { Map<String, UIComponent> map = list.getFacets(); UIComponent component = map.get(facetType); if (component != null) { String headerValue = null; if (component instanceof HtmlCommandButton) { headerValue = exportValue(context, component); } else if (component instanceof HtmlCommandLink) { headerValue = exportValue(context, component); } else {/*w w w . j a va 2 s. c o m*/ headerValue = exportFacetValue(context, component); } int sheetRowIndex = sheet.getLastRowNum() + 1; Row row = sheet.createRow(sheetRowIndex); Cell cell = row.createCell((short) 0); cell.setCellValue(headerValue); cell.setCellStyle(facetStyle); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex, //last row (0-based) 0, //first column (0-based) 1 //last column (0-based) )); } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void tableColumnGroup(Sheet sheet, DataTable table, String facetType) { ColumnGroup cg = table.getColumnGroup(facetType); List<UIComponent> headerComponentList = null; if (cg != null) { headerComponentList = cg.getChildren(); }/* w w w . ja va 2 s . co m*/ if (headerComponentList != null) { for (UIComponent component : headerComponentList) { if (component instanceof org.primefaces.component.row.Row) { org.primefaces.component.row.Row row = (org.primefaces.component.row.Row) component; int sheetRowIndex = sheet.getLastRowNum() + 1; Row xlRow = sheet.createRow(sheetRowIndex); int i = 0; for (UIComponent rowComponent : row.getChildren()) { UIColumn column = (UIColumn) rowComponent; String value = null; if (facetType.equalsIgnoreCase("header")) { value = column.getHeaderText(); } else { value = column.getFooterText(); } int rowSpan = column.getRowspan(); int colSpan = column.getColspan(); Cell cell = xlRow.getCell(i); if (rowSpan > 1 || colSpan > 1) { if (rowSpan > 1) { cell = xlRow.createCell((short) i); Boolean rowSpanFlag = false; for (int j = 0; j < sheet.getNumMergedRegions(); j++) { CellRangeAddress merged = sheet.getMergedRegion(j); if (merged.isInRange(sheetRowIndex, i)) { rowSpanFlag = true; } } if (!rowSpanFlag) { cell.setCellValue(value); cell.setCellStyle(facetStyle); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex + (rowSpan - 1), //last row (0-based) i, //first column (0-based) i //last column (0-based) )); } } if (colSpan > 1) { cell = xlRow.createCell((short) i); for (int j = 0; j < sheet.getNumMergedRegions(); j++) { CellRangeAddress merged = sheet.getMergedRegion(j); if (merged.isInRange(sheetRowIndex, i)) { cell = xlRow.createCell((short) ++i); } } cell.setCellValue(value); cell.setCellStyle(facetStyle); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex, //last row (0-based) i, //first column (0-based) i + (colSpan - 1) //last column (0-based) )); i = i + colSpan - 1; } } else { cell = xlRow.createCell((short) i); for (int j = 0; j < sheet.getNumMergedRegions(); j++) { CellRangeAddress merged = sheet.getMergedRegion(j); if (merged.isInRange(sheetRowIndex, i)) { cell = xlRow.createCell((short) ++i); } } cell.setCellValue(value); cell.setCellStyle(facetStyle); } i++; } } } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void tableColumnGroup(Sheet sheet, SubTable table, String facetType) { ColumnGroup cg = table.getColumnGroup(facetType); List<UIComponent> headerComponentList = null; if (cg != null) { headerComponentList = cg.getChildren(); }/*from ww w . j av a 2 s.co m*/ if (headerComponentList != null) { for (UIComponent component : headerComponentList) { if (component instanceof org.primefaces.component.row.Row) { org.primefaces.component.row.Row row = (org.primefaces.component.row.Row) component; int sheetRowIndex = sheet.getLastRowNum() + 1; Row xlRow = sheet.createRow(sheetRowIndex); int i = 0; for (UIComponent rowComponent : row.getChildren()) { UIColumn column = (UIColumn) rowComponent; String value = null; if (facetType.equalsIgnoreCase("header")) { value = column.getHeaderText(); } else { value = column.getFooterText(); } int rowSpan = column.getRowspan(); int colSpan = column.getColspan(); Cell cell = xlRow.getCell(i); if (rowSpan > 1 || colSpan > 1) { if (rowSpan > 1) { cell = xlRow.createCell((short) i); Boolean rowSpanFlag = false; for (int j = 0; j < sheet.getNumMergedRegions(); j++) { CellRangeAddress merged = sheet.getMergedRegion(j); if (merged.isInRange(sheetRowIndex, i)) { rowSpanFlag = true; } } if (!rowSpanFlag) { cell.setCellStyle(cellStyle); cell.setCellValue(value); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex + rowSpan - 1, //last row (0-based) i, //first column (0-based) i //last column (0-based) )); } } if (colSpan > 1) { cell = xlRow.createCell((short) i); for (int j = 0; j < sheet.getNumMergedRegions(); j++) { CellRangeAddress merged = sheet.getMergedRegion(j); if (merged.isInRange(sheetRowIndex, i)) { cell = xlRow.createCell((short) ++i); } } cell.setCellStyle(cellStyle); cell.setCellValue(value); sheet.addMergedRegion(new CellRangeAddress(sheetRowIndex, //first row (0-based) sheetRowIndex, //last row (0-based) i, //first column (0-based) i + colSpan - 1 //last column (0-based) )); i = i + colSpan - 1; } } else { cell = xlRow.createCell((short) i); for (int j = 0; j < sheet.getNumMergedRegions(); j++) { CellRangeAddress merged = sheet.getMergedRegion(j); if (merged.isInRange(sheetRowIndex, i)) { cell = xlRow.createCell((short) ++i); } } cell.setCellValue(value); cell.setCellStyle(facetStyle); } i++; } } } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void exportCells(DataTable table, Sheet sheet, int rowIndex) { int sheetRowIndex = sheet.getLastRowNum() + 1; Row row = sheet.createRow(sheetRowIndex); for (UIColumn col : table.getColumns()) { if (!col.isRendered()) { continue; }//from w ww .j a v a 2 s .c o m if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyModel(); } if (col.isExportable()) { //Adding RowIndex for custom Export UIComponent component = (UIComponent) col; if (component.getId().equalsIgnoreCase("subject")) { Cell cell = row.createCell(0); String value = rowIndex + ""; cell.setCellValue(new XSSFRichTextString(value)); } addColumnValue(row, col.getChildren(), "content"); } } FacesContext context = null; if (table.getRowIndex() == 0) { for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); childTable.setRowIndex(-1); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList childList = (DataList) rowExpansion.getChildren().get(0); childList.setRowIndex(-1); } } } } } table.setRowIndex(table.getRowIndex() + 1); for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList list = (DataList) rowExpansion.getChildren().get(0); if (list.getHeader() != null) { tableFacet(context, sheet, list, "header"); } exportAll(context, list, sheet); } if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); int columnsCount = getColumnsCount(childTable); if (childTable.getHeader() != null) { tableFacet(context, sheet, childTable, columnsCount, "header"); } tableColumnGroup(sheet, childTable, "header"); addColumnFacets(childTable, sheet, ColumnType.HEADER); exportAll(context, childTable, sheet, false); if (childTable.hasFooterColumn()) { addColumnFacets(childTable, sheet, ColumnType.FOOTER); } tableColumnGroup(sheet, childTable, "footer"); childTable.setRowIndex(-1); } } } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void exportCells(DataList list, Sheet sheet) { int sheetRowIndex = sheet.getLastRowNum() + 1; Row row = sheet.createRow(sheetRowIndex); for (UIComponent component : list.getChildren()) { if (component instanceof Column) { UIColumn column = (UIColumn) component; for (UIComponent childComponent : column.getChildren()) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); if (component.isRendered()) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), childComponent); cell.setCellValue(new XSSFRichTextString(value)); cell.setCellStyle(cellStyle); }//from w w w . j a v a 2 s. c om } } else { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); if (component.isRendered()) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); cell.setCellValue(new XSSFRichTextString(value)); cell.setCellStyle(cellStyle); } } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void addColumnFacets(DataTable table, Sheet sheet, ColumnType columnType) { int sheetRowIndex = sheet.getLastRowNum() + 1; Row rowHeader = sheet.createRow(sheetRowIndex); for (UIColumn col : table.getColumns()) { if (!col.isRendered()) { continue; }// ww w. j ava 2 s .com if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyModel(); } if (col.isExportable()) { //Adding RowIndex for custom Export UIComponent component = (UIComponent) col; if (component.getId().equalsIgnoreCase("subject")) { Cell cell = rowHeader.createCell(0); String value = "Index"; cell.setCellValue(new XSSFRichTextString(value)); } //Adding RowIndex for custom Export addColumnValue(rowHeader, col.getFacet(columnType.facet()), "facet"); } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void addColumnValue(Row row, UIComponent component, String type) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); cell.setCellValue(new XSSFRichTextString(value)); if (type.equalsIgnoreCase("facet")) { // addColumnAlignments(component,facetStyle); cell.setCellStyle(facetStyle);//w ww .j av a2s . c om } else { CellStyle cellStyle = this.cellStyle; cellStyle = addColumnAlignments(component, cellStyle); cell.setCellStyle(cellStyle); } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void addColumnValue(Row row, List<UIComponent> components, String type) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); StringBuilder builder = new StringBuilder(); FacesContext context = FacesContext.getCurrentInstance(); for (UIComponent component : components) { if (component.isRendered()) { String value = exportValue(context, component); if (value != null) { builder.append(value);/*from ww w . jav a2 s. co m*/ } } } cell.setCellValue(new XSSFRichTextString(builder.toString())); if (type.equalsIgnoreCase("facet")) { //addColumnAlignments(components,facetStyle); cell.setCellStyle(facetStyle); } else { CellStyle cellStyle = this.cellStyle; for (UIComponent component : components) { cellStyle = addColumnAlignments(component, cellStyle); cell.setCellStyle(cellStyle); } } }