List of usage examples for org.apache.poi.ss.util CellRangeAddress CellRangeAddress
public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol)
From source file:org.sharegov.cirm.utils.ExcelExportUtil.java
License:Apache License
public Integer searchCriteriaRows1(Json searchCriteria, HSSFCellStyle boldCenterStyle, int totalRecords) { int rowCounter = 0; int cellCounter = 0; //Create Headings and info about the report HSSFRow row = sheet.createRow(rowCounter++); HSSFCell cell = row.createCell(cellCounter++); cell.setCellValue(basicSearchReportHeader); cell.setCellStyle(boldCenterStyle);// w w w. j a va 2s.c om sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 3)); row = sheet.createRow(rowCounter++); cellCounter = 0; cell = row.createCell(cellCounter++); cell.setCellValue(searchCriteriaHeader); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 2)); for (Entry<String, Json> prop : searchCriteria.asJsonMap().entrySet()) { row = sheet.createRow(rowCounter++); cellCounter = 0; cell = row.createCell(cellCounter++); cell.setCellValue(prop.getKey()); cell = row.createCell(cellCounter++); cell.setCellValue(prop.getValue().asString()); } row = sheet.createRow(rowCounter++); row = sheet.createRow(rowCounter++); cellCounter = 0; cell = row.createCell(cellCounter++); cell.setCellValue(totalResults + " : " + totalRecords); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 1)); row = sheet.createRow(rowCounter++); return rowCounter; }
From source file:org.sharegov.cirm.utils.ExcelExportUtil.java
License:Apache License
public Integer searchCriteriaRows(Json allData, HSSFCellStyle boldStyle) { Json basicSCLabels = Json.object().set("type", "SR Type").set("legacy:hasCaseNumber", "SR ID") .set("atAddress", "Address").set("isCreatedBy", "Input By").set("name", "First Name") .set("lastName", "Last Name").set("legacy:hasStatus", "Status") .set("legacy:hasIntakeMethod", "Intake Method").set("legacy:hasPriority", "Priority") .set("serviceQuestion", "SR Question").set("legacy:hasDueDate", "Over Due Date") .set("hasDateCreated", "Created Date").set("legacy:hasServiceCaseActor", "Customer Name") .set("gisColumnName", ""); Json searchCriteria = allData.at("searchCriteria"); OWLOntology ont = ontology();/*from w ww. ja v a 2 s. c o m*/ int rowCounter = 0; //int cellCounter = 0; //Create Headings and info about the report HSSFRow row = sheet.createRow(rowCounter++); HSSFCell cell = row.createCell(0); cell.setCellValue(basicSearchReportHeader); cell.setCellStyle(boldStyle); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 3)); row = sheet.createRow(rowCounter++); row = sheet.createRow(rowCounter++); // cellCounter = 0; cell = row.createCell(0); cell.setCellValue(searchCriteriaHeader); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 2)); for (Entry<String, Json> prop : searchCriteria.asJsonMap().entrySet()) { if (prop.getKey().equalsIgnoreCase("sortBy") || prop.getKey().equalsIgnoreCase("caseSensitive") || prop.getKey().equalsIgnoreCase("sortDirection") || prop.getKey().equalsIgnoreCase("currentPage") || prop.getKey().equalsIgnoreCase("itemsPerPage")) continue; if (prop.getKey().equalsIgnoreCase("type")) { if (prop.getValue().isString() && prop.getValue().asString().equalsIgnoreCase("legacy:ServiceCase")) continue; if (prop.getValue().isArray()) { List<Json> typeList = prop.getValue().asJsonList(); if (typeList.size() == 1 && typeList.get(0).asString().equalsIgnoreCase("legacy:ServiceCase")) continue; } } StringBuilder sbQuestion = new StringBuilder(""); StringBuilder sbAnswer = new StringBuilder(""); sbQuestion.append( basicSCLabels.has(prop.getKey()) ? basicSCLabels.at(prop.getKey()).asString() : prop.getKey()); if (prop.getKey().equalsIgnoreCase("type")) { //sbAnswer.append(getEntityLabel(individual(prop.getValue().asString()))); sbAnswer.append("SR TYPE"); } else if (ont.isDeclared(dataProperty(fullIri(prop.getKey())), true)) { sbAnswer.append(prop.getValue().asString()); } else if (ont.isDeclared(objectProperty(fullIri(prop.getKey())), true)) { if (prop.getKey().equals("legacy:hasStatus") || prop.getKey().equals("legacy:hasIntakeMethod") || prop.getKey().equals("legacy:hasPriority")) { sbAnswer.append(getEntityLabel(individual(prop.getValue().at("iri").asString()))); } if (prop.getKey().equals("atAddress")) { if (prop.getValue().has("fullAddress")) sbAnswer.append(prop.getValue().at("fullAddress").asString()); if (prop.getValue().has("Street_Unit_Number")) sbAnswer.append("#").append(prop.getValue().at("Street_Unit_Number").asString()); if (prop.getValue().has("Street_Address_City")) sbAnswer.append(", ").append(ServiceRequestReportUtil.getCity(prop.getValue())); if (prop.getValue().has("Zip_Code")) sbAnswer.append(" - ").append(prop.getValue().at("Zip_Code").asString()); } else if (prop.getKey().equals("legacy:hasServiceCaseActor")) { if (prop.getValue().has("Name")) sbAnswer.append(prop.getValue().at("Name").asString()); if (prop.getValue().has("LastName")) sbAnswer.append(" ").append(prop.getValue().at("LastName").asString()); } else if (prop.getKey().equals("hasGeoPropertySet")) { sbQuestion = new StringBuilder(""); for (Entry<String, Json> geoProp : prop.getValue().asJsonMap().entrySet()) { if (geoProp.getKey().equals("type")) continue; else { sbQuestion.append(geoProp.getKey()); sbAnswer.append(geoProp.getValue().asString()); } } } } else if (ont.containsIndividualInSignature(fullIri(prop.getKey()), true)) { sbQuestion = new StringBuilder(""); sbQuestion.append(getEntityLabel(individual(prop.getKey()))); if (prop.getValue().isString()) sbAnswer.append(getEntityLabel(individual(prop.getValue().asString()))); else if (prop.getValue().isObject()) sbAnswer.append(prop.getValue().at("literal").asString()); } else { continue; } row = sheet.createRow(rowCounter++); // cellCounter = 0; cell = row.createCell(0); cell.setCellValue(sbQuestion.toString()); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 1)); cell = row.createCell(2); cell.setCellValue(sbAnswer.toString()); sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), cell.getColumnIndex(), cell.getColumnIndex() + 1)); } row = sheet.createRow(rowCounter++); row = sheet.createRow(rowCounter++); // cellCounter = 0; cell = row.createCell(0); cell.setCellValue(totalResults); cell.setCellStyle(boldStyle); cell = row.createCell(1); cell.setCellValue(allData.at("data").asJsonList().size()); // boldStyle.setFillForegroundColor(HSSFColor.YELLOW.index); // boldStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cell.setCellStyle(boldStyle); row = sheet.createRow(rowCounter++); return rowCounter; }
From source file:org.sigmah.server.endpoint.export.Export.java
License:Open Source License
private void createHeaders(ActivityDTO activity, HSSFSheet sheet) { /// The HEADER rows Row headerRow1 = sheet.createRow(0); Row headerRow2 = sheet.createRow(1); headerRow2.setHeightInPoints(75);//from w ww. j a v a 2 s.c o m int column = 0; createHeaderCell(headerRow2, column++, "Date1", CellStyle.ALIGN_RIGHT); createHeaderCell(headerRow2, column++, "Date2", CellStyle.ALIGN_RIGHT); createHeaderCell(headerRow2, column, "Partner"); sheet.setColumnWidth(column, 16 * 256); column++; createHeaderCell(headerRow2, column, activity.getLocationType().getName()); sheet.setColumnWidth(column, 20 * 256); column++; createHeaderCell(headerRow2, column++, "Axe"); indicators = new ArrayList<Integer>(activity.getIndicators().size()); if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) { for (IndicatorGroup group : activity.groupIndicators()) { if (group.getName() != null) { // create a merged cell on the top row spanning all members of the group createHeaderCell(headerRow1, column, group.getName()); sheet.addMergedRegion( new CellRangeAddress(0, 0, column, column + group.getIndicators().size() - 1)); } for (IndicatorDTO indicator : group.getIndicators()) { indicators.add(indicator.getId()); createHeaderCell(headerRow2, column, indicator.getName(), indicatorHeaderStyle); sheet.setColumnWidth(column, 16 * 256); column++; } } } attributes = new ArrayList<Integer>(); int firstAttributeColumn = column; for (AttributeGroupDTO group : activity.getAttributeGroups()) { if (group.getAttributes().size() != 0) { createHeaderCell(headerRow1, column, group.getName(), CellStyle.ALIGN_CENTER); sheet.addMergedRegion( new CellRangeAddress(0, 0, column, column + group.getAttributes().size() - 1)); for (AttributeDTO attrib : group.getAttributes()) { attributes.add(attrib.getId()); createHeaderCell(headerRow2, column, attrib.getName(), attribHeaderStyle); sheet.setColumnWidth(column, 5 * 256); column++; } } } // sheet.getSheetConditionalFormatting().addConditionalFormatting( // new CellRangeAddress[] { new CellRangeAddress(2, 65535, firstAttributeColumn, column-1) }, // new HSSFConditionalFormattingRule[] { attribTrueRule, attribFalseRule }); levels = new ArrayList<Integer>(); for (AdminLevelDTO level : activity.getAdminLevels()) { createHeaderCell(headerRow2, column++, "Code " + level.getName()); createHeaderCell(headerRow2, column++, level.getName()); levels.add(level.getId()); } createHeaderCell(headerRow2, column, "Longitude", CellStyle.ALIGN_RIGHT); createHeaderCell(headerRow2, column + 1, "Latitude", CellStyle.ALIGN_RIGHT); sheet.setColumnWidth(column, 12 * 256); sheet.setColumnWidth(column + 1, 12 * 256); }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public void putMainTitle(final HSSFSheet sheet, int rowIndex, String text, int maxCols) { // title/* w ww . j a v a2 s . c o m*/ row = sheet.createRow(rowIndex); row.setHeightInPoints(ExportConstants.HEADER_ROW_HEIGHT); cell = row.createCell(1); cell.setCellValue(text); cell.setCellStyle(getTopicStyle(wb)); sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, maxCols)); }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public void putInfoRow(final HSSFSheet sheet, int rowIndex, String key, String value, int maxCols) { int cellIndex = 0; row = sheet.createRow(rowIndex);//from w w w . java2 s . com row.setHeightInPoints(ExportConstants.TITLE_ROW_HEIGHT); cell = row.createCell(++cellIndex); cell.setCellValue(key); cell.setCellStyle(getInfoStyle(wb, true)); cell = row.createCell(++cellIndex); cell.setCellValue(value); cell.setCellStyle(getInfoStyle(wb, false)); sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, cellIndex, maxCols)); }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.template.BaseSynthesisExcelTemplate.java
License:Open Source License
private int putLayout(final HSSFSheet sheet, final Layout layout, int rowIndex) throws Throwable { int typeStartRow = rowIndex; boolean firstGroup = true; // layout groups for each phase for (final LayoutGroup layoutGroup : layout.getGroups()) { // layout group cell if (!firstGroup) { row = sheet.createRow(++rowIndex); }/*from w w w .ja v a 2s . c o m*/ firstGroup = false; row.setHeightInPoints(ExportConstants.TITLE_ROW_HEIGHT); CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex, 2, data.getNumbOfCols()); sheet.addMergedRegion(utils.getBorderedRegion(region, sheet, wb)); cell = sheet.getRow(rowIndex).createCell(2); cell.setCellStyle(utils.getGroupStyle(wb)); cell.setCellValue(layoutGroup.getTitle()); // elements for each layout group for (final LayoutConstraint constraint : layoutGroup.getConstraints()) { final FlexibleElement element = constraint.getElement(); // skip if element is not exportable if (!element.isExportable()) continue; final String elementName = "element." + element.getClass().getSimpleName(); Integer id = (clazz.equals(Project.class)) ? data.getProject().getId() : data.getOrgUnit().getId(); final GetValue command = new GetValue(id, element.getId(), elementName, null); final ValueResult valueResult = (ValueResult) data.getHandler().execute(command, null); // prepare value and label ValueLabel pair = null; boolean isMessage = false; /* DEF FLEXIBLE */ if (elementName.equals("element.DefaultFlexibleElement") || elementName.equals("element.BudgetElement")) { pair = data.getDataProvider().getDefElementPair(valueResult, element, data.getProject() != null ? data.getProject() : data.getOrgUnit(), clazz, data.getEntityManager(), data.getLocale(), data.getTranslator()); } /* CHECKBOX */else if (elementName.equals("element.CheckboxElement")) { pair = data.getDataProvider().getCheckboxElementPair(valueResult, element, data.getLocale(), data.getTranslator()); } /* TEXT AREA */else if (elementName.equals("element.TextAreaElement")) { pair = data.getDataProvider().getTextAreaElementPair(valueResult, element); } /* TRIPLET */else if (elementName.equals("element.TripletsListElement")) { pair = data.getDataProvider().getTripletPair(element, valueResult); } /* CHOICE */else if (elementName.equals("element.QuestionElement")) { pair = data.getDataProvider().getChoicePair(element, valueResult); } /* MESSAGE */else if (elementName.equals("element.MessageElement")) { pair = new ValueLabel(data.getLocalizedVersion("flexibleElementMessage"), GlobalExportDataProvider.clearHtmlFormatting(element.getLabel())); isMessage = true; } if (pair != null) putElement(sheet, ++rowIndex, pair, isMessage); } // elements } region = new CellRangeAddress(typeStartRow, rowIndex, 1, 1); sheet.addMergedRegion(utils.getBorderedRegion(region, sheet, wb)); return rowIndex; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.template.IndicatorEntryExcelTemplate.java
License:Open Source License
private void createDetailSheet(final IndicatorDTO indicator) { final boolean isQualitative = indicator.getAggregation() == IndicatorDTO.AGGREGATE_MULTINOMIAL; final HSSFSheet sheetEx = wb .createSheet(utils.normalizeAsLink(ExportConstants.INDICATOR_SHEET_PREFIX + indicator.getName())); int rowIndex = -1; final List<PivotTableData.Axis> leaves = data.getEntryMap().get(indicator.getId()).getRootColumn() .getLeaves();/*from ww w . jav a 2 s . c o m*/ int numbOfLeaves = leaves.size(); int numbOfCols = 4; //back to list link row = sheetEx.createRow(++rowIndex); utils.createLinkCell(row.createCell(1), data.getLocalizedVersion("goToIndicatorsList"), data.getLocalizedVersion("flexibleElementIndicatorsList"), false); sheetEx.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, numbOfCols)); //title utils.putMainTitle(sheetEx, ++rowIndex, indicator.getName(), numbOfCols); //empty row utils.putEmptyRow(sheetEx, ++rowIndex, ExportConstants.EMPTY_ROW_HEIGHT); sheetEx.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, numbOfCols)); //put details putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("code"), indicator.getCode(), numbOfCols); putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("group"), data.getGroupMap().get(indicator.getGroupId()), numbOfCols); //type String type = null; ; if (isQualitative) { //qualitative type = data.getLocalizedVersion("qualitative"); } else { //quantitative type = data.getLocalizedVersion("quantitative"); } putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("type"), type, numbOfCols); //conditional if (isQualitative) { //qualitative //possible values row = sheetEx.createRow(++rowIndex); //key cell = utils.putHeader(row, 1, data.getLocalizedVersion("possibleValues")); cell.getCellStyle().setAlignment(CellStyle.ALIGN_RIGHT); //value final MultiItemText itemText = data.formatPossibleValues(indicator.getLabels()); utils.putBorderedBasicCell(sheetEx, rowIndex, 2, itemText.text); row.setHeightInPoints(itemText.lineCount * defHeight); region = new CellRangeAddress(rowIndex, rowIndex, 2, numbOfCols); sheetEx.addMergedRegion(utils.getBorderedRegion(region, sheetEx, wb)); } else { //quantitative //aggregation method String aggrMethod = null; if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_AVG) aggrMethod = data.getLocalizedVersion("average"); else aggrMethod = data.getLocalizedVersion("sum"); putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("aggregationMethod"), aggrMethod, numbOfCols); //units putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("units"), indicator.getUnits(), numbOfCols); //target value putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("targetValue"), indicator.getObjective(), numbOfCols); } //source of ver putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("sourceOfVerification"), indicator.getSourceOfVerification(), numbOfCols); row.setHeightInPoints(utils.calculateLineCount(indicator.getSourceOfVerification(), 3 * 18) * defHeight); //comment putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("indicatorComments"), indicator.getDescription(), numbOfCols); row.setHeightInPoints(utils.calculateLineCount(indicator.getDescription(), 3 * 18) * defHeight); //value putBasicInfo(sheetEx, ++rowIndex, data.getLocalizedVersion("value"), data.getFormattedValue(indicator), numbOfCols); //empty row utils.putEmptyRow(sheetEx, ++rowIndex, ExportConstants.EMPTY_ROW_HEIGHT); sheetEx.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, numbOfCols)); //data entry //header row = sheetEx.createRow(++rowIndex); row.setHeightInPoints(defHeight); int cellIndex = 0; utils.putHeader(row, ++cellIndex, data.getLocalizedVersion("sideAndMonth")); Map<String, Integer> columnIndexMap = new HashMap<String, Integer>(); for (PivotTableData.Axis axis : leaves) { utils.putHeader(row, ++cellIndex, axis.getLabel()); columnIndexMap.put(axis.getLabel(), cellIndex); } //rows for (PivotTableData.Axis axis : data.getEntryMap().get(indicator.getId()).getRootRow().getChildren()) { row = sheetEx.createRow(++rowIndex); row.setHeightInPoints(defHeight); utils.putHeader(row, 1, axis.getLabel()); //populate empty cells for (int i = 0; i < numbOfLeaves; i++) { cell = utils.putBorderedBasicCell(sheetEx, rowIndex, i + 2, ""); } //insert values for (Map.Entry<PivotTableData.Axis, PivotTableData.Cell> entry : axis.getCells().entrySet()) { cellIndex = columnIndexMap.get(entry.getKey().getLabel()); Object value = null; boolean rightAligned = false; if (isQualitative) { value = data.getLabelByIndex(indicator.getLabels(), entry.getValue().getValue()); } else { value = new Long(Math.round(entry.getValue().getValue())); rightAligned = true; } putValueCell(sheetEx, rowIndex, cellIndex, value, rightAligned); } } //col width sheetEx.setColumnWidth(0, 256 * 2); sheetEx.autoSizeColumn(1); for (int i = 2; i < 2 + numbOfLeaves; i++) { sheetEx.setColumnWidth(i, 256 * 16); } }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.template.IndicatorEntryExcelTemplate.java
License:Open Source License
private void putBasicInfo(HSSFSheet sheet, int rowIndex, String key, Object value, int numbOfCols) { row = sheet.createRow(rowIndex);/*from w w w .j av a 2 s . co m*/ row.setHeightInPoints(defHeight); //key cell = utils.putHeader(row, 1, key); cell.getCellStyle().setAlignment(CellStyle.ALIGN_RIGHT); //value utils.putBorderedBasicCell(sheet, rowIndex, 2, value); region = new CellRangeAddress(rowIndex, rowIndex, 2, numbOfCols); sheet.addMergedRegion(utils.getBorderedRegion(region, sheet, wb)); }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.template.IndicatorEntryExcelTemplate.java
License:Open Source License
private void putGroupCell(HSSFSheet sheet, int rowIndex, String name) { cell = sheet.getRow(rowIndex).createCell(1); cell.setCellValue(name);/*from w ww . ja va 2 s.c o m*/ CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex, 1, data.getNumbOfCols()); sheet.addMergedRegion(utils.getBorderedRegion(region, sheet, wb)); cell.setCellStyle(utils.getGroupStyle(wb)); }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.template.LogFrameExcelTemplate.java
License:Open Source License
private void mergeCell(int startRow, int endRow, int startCol, int endCol) { region = new CellRangeAddress(startRow, endRow, startCol, endCol); sheet.addMergedRegion(utils.getBorderedRegion(region, sheet, wb)); }