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:fi.thl.pivot.export.XlsxExporter.java
@SuppressWarnings("unchecked") private int printFilters(Map<String, ?> params, Sheet sheet, int initialRowNumber, int columns) { int rowNumber = initialRowNumber + 2; Row r = sheet.createRow(rowNumber);//from w w w.ja v a 2s. co m Cell c1 = r.createCell(0); c1.setCellValue(message("cube.filter.selected", "")); c1.setCellStyle(defaultStyle); sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, columns - 1)); for (Dimension d : (Collection<Dimension>) params.get("dimensions")) { for (IDimensionNode f : (Collection<IDimensionNode>) params.get("filters")) { if (f.getDimension().getId().equals(d.getId())) { Row filterRow = sheet.createRow(++rowNumber); Cell cell1 = filterRow.createCell(0); cell1.setCellStyle(defaultStyle); cell1.setCellValue(d.getLabel().getValue(language)); Cell cell2 = filterRow.createCell(1); cell2.setCellStyle(defaultStyle); cell2.setCellValue(f.getLabel().getValue(language)); sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 1, columns - 1)); } } } return rowNumber; }
From source file:fi.thl.pivot.export.XlsxExporter.java
private void mergeInColumn(Sheet sheet, int rowNumber, int firstColumnWithSameHeader, int lastColumnWithSameHeader) { if (lastColumnWithSameHeader - firstColumnWithSameHeader > 0) { sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, firstColumnWithSameHeader, lastColumnWithSameHeader)); }/*from ww w. j a v a2 s. c o m*/ }
From source file:fi.thl.pivot.export.XlsxExporter.java
private void mergeInRow(Sheet sheet, int columnNumber, int firstRowWithSameHeader, int lastRowWithSameHeader) { if (lastRowWithSameHeader - firstRowWithSameHeader > 0) { sheet.addMergedRegion(new CellRangeAddress(firstRowWithSameHeader, lastRowWithSameHeader, columnNumber, columnNumber));//from w w w . j a va 2s. co m } }
From source file:fr.amapj.service.engine.generator.excel.ExcelGeneratorTool.java
License:Open Source License
/** * Merge des cellules//from ww w . j a va2 s . c om * * Le style de la cellule en haut gauche est copi sur toutes les autres cellules * * @param firstRow * @param lastRow * @param firstCol * @param lastCol */ public void mergeCells(int firstRow, int lastRow, int firstCol, int lastCol) { CellStyle style = sheet.getRow(firstRow).getCell(firstCol).getCellStyle(); for (int numRow = firstRow; numRow <= lastRow; numRow++) { Row row = sheet.getRow(numRow); for (int numCol = firstCol; numCol <= lastCol; numCol++) { row.getCell(numCol).setCellStyle(style); } } sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol)); }
From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java
License:Apache License
/** * Ajoute les en-ttes dans la feuille de calcul et cache les colonnes qui doivent l'tre. * //w w w . ja va2 s. c om * @param sheet feuille de calcul * @param rowIndex numro de la ligne * @param columnInfos RangeMap contenant les informations de colonnes (valeurs) et les index sur auxquelles s'appliquent ces colonnes (cls). * Les "colonnes" s'tendant sur plus d'un index seront automatiquement fusionnes. */ protected void addHeadersToSheet(Sheet sheet, int rowIndex, RangeMap<Integer, ColumnInformation> columnInfos) { Row rowHeader = sheet.createRow(rowIndex); for (Map.Entry<Range<Integer>, ColumnInformation> entry : columnInfos.asMapOfRanges().entrySet()) { Range<Integer> range = entry.getKey(); ColumnInformation columnInformation = entry.getValue(); addHeaderCell(rowHeader, range.lowerEndpoint(), getColumnLabel(columnInformation.getHeaderKey())); for (Integer columnIndex : ContiguousSet.create(range, DiscreteDomain.integers())) { sheet.setColumnHidden(columnIndex, columnInformation.isHidden()); } int beginIndex = range.lowerEndpoint(); int endIndex = range.upperEndpoint(); if (beginIndex != endIndex) { sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, beginIndex, endIndex)); } } }
From source file:functions.excels.Excel.java
License:Apache License
protected void collerLogoEtTitre(int page, String titre) throws IOException { // TODO Auto-generated method stub Sheet sheet = wb.getSheetAt(0);//w ww. j a v a 2 s. c om sheet.createRow(page * LIGNES + 3).createCell(4).setCellValue(titre); sheet.addMergedRegion(new CellRangeAddress(page * LIGNES + 3, //first row (0-based) page * LIGNES + 5, //last row (0-based) 4, //first column (0-based) 8 //last column (0-based) )); this.collerLogo(page); }
From source file:functions.excels.exports.CarteSommeBiodiversiteExcel.java
License:Apache License
public CarteSommeBiodiversiteExcel(Map<String, String> info, CarteSommeBiodiversite csb) { super();// ww w . j a v a 2 s . co m Sheet sheet = wb.createSheet("Carte somme de la biodiversit"); Espece espece = Espece.find.byId(Integer.parseInt(info.get("espece"))); SousGroupe sous_groupe = SousGroupe.find.byId(Integer.parseInt(info.get("sous_groupe"))); Groupe groupe = Groupe.find.byId(Integer.parseInt(info.get("groupe"))); StadeSexe stade_sexe = StadeSexe.find.byId(Integer.parseInt(info.get("stade"))); String date1 = info.get("jour1") + "/" + info.get("mois1") + "/" + info.get("annee1"); String date2 = info.get("jour2") + "/" + info.get("mois2") + "/" + info.get("annee2"); String titre = "Carte indiquant les premires observations "; if (espece != null) titre += "de " + espece.espece_nom; else if (sous_groupe != null) titre += "de " + sous_groupe; else if (groupe != null) titre += "de " + groupe; if (stade_sexe != null) titre += " au stade " + stade_sexe; titre += " du " + date1 + " au " + date2; sheet.createRow(0).createCell(0).setCellValue(titre); sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) 12 //last column (0-based) )); Row rowHead = sheet.createRow(1); rowHead.createCell(0).setCellValue("UTM"); rowHead.createCell(1).setCellValue("Fiche ID"); rowHead.createCell(2).setCellValue("Espce"); rowHead.createCell(3).setCellValue("Date"); rowHead.createCell(4).setCellValue("Tmoin(s)"); CellStyle cellStyleDate = wb.createCellStyle(); CreationHelper creationHelper = wb.getCreationHelper(); cellStyleDate.setDataFormat(creationHelper.createDataFormat().getFormat("dd/mm/yyyy")); int i = 2; for (UTMS utm : UTMS.findAll()) { List<List<InformationsComplementaires>> observationsDansCetteMaille = csb.carte.get(utm); for (List<InformationsComplementaires> observationsPourCetteEspece : observationsDansCetteMaille) { for (InformationsComplementaires complements : observationsPourCetteEspece) { Row row = sheet.createRow(i); row.createCell(0).setCellValue(utm.utm); row.createCell(1).setCellValue( complements.informations_complementaires_observation.observation_fiche.fiche_id); row.createCell(2).setCellValue( complements.informations_complementaires_observation.observation_espece.espece_nom); Cell cellDate = row.createCell(3); cellDate.setCellValue( complements.informations_complementaires_observation.observation_fiche.fiche_date); cellDate.setCellStyle(cellStyleDate); StringBuilder membres = new StringBuilder(); List<FicheHasMembre> fhms = complements.informations_complementaires_observation.observation_fiche .getFicheHasMembre(); for (int j = 0; j < fhms.size() - 1; j++) { membres.append(fhms.get(j).membre); membres.append(", "); } if (!fhms.isEmpty()) membres.append(fhms.get(fhms.size() - 1).membre); else membres.append("et al."); row.createCell(4).setCellValue(membres.toString()); i++; } } } sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); sheet.autoSizeColumn(2); sheet.autoSizeColumn(3); for (int k = 1; k <= 20; k++) { if (sheet.getRow(k) == null) sheet.createRow(k); } CellStyle redBackGround = wb.createCellStyle(); redBackGround.setFillBackgroundColor(IndexedColors.RED.getIndex()); redBackGround.setFillPattern(CellStyle.BIG_SPOTS); for (UTMS utm : csb.carte.keySet()) { int xy[] = UTMtoXY.convert10x10(utm.utm); Row row = sheet.getRow(xy[1] + 1); Cell cell = row.createCell(xy[0] + 5); int nombreDEspeces = csb.getNombreDEspecesDansMaille(utm); cell.setCellValue(nombreDEspeces); if (nombreDEspeces != 0) cell.setCellStyle(redBackGround); } for (int k = 5; k < 25; k++) { sheet.autoSizeColumn(k); } Row rowUniteMailleEspece; if ((rowUniteMailleEspece = sheet.getRow(23)) == null) rowUniteMailleEspece = sheet.createRow(23); rowUniteMailleEspece.createCell(6).setCellValue("Units maille-espce : " + csb.getUnitesMailleEspece()); }
From source file:functions.excels.exports.CarteSommeExcel.java
License:Apache License
public CarteSommeExcel(Map<String, String> info, CarteSomme cs) { super();//from w w w .ja v a2s. c o m Sheet sheet = wb.createSheet("Carte somme"); Espece espece = Espece.find.byId(Integer.parseInt(info.get("espece"))); SousGroupe sous_groupe = SousGroupe.find.byId(Integer.parseInt(info.get("sous_groupe"))); Groupe groupe = Groupe.find.byId(Integer.parseInt(info.get("groupe"))); StadeSexe stade_sexe = StadeSexe.find.byId(Integer.parseInt(info.get("stade"))); String date1 = info.get("jour1") + "/" + info.get("mois1") + "/" + info.get("annee1"); String date2 = info.get("jour2") + "/" + info.get("mois2") + "/" + info.get("annee2"); String titre = "Carte indiquant le nombre d'observations "; if (espece != null) titre += "de " + espece.espece_nom; else if (sous_groupe != null) titre += "de " + sous_groupe; else if (groupe != null) titre += "de " + groupe; if (stade_sexe != null) titre += " au stade " + stade_sexe; titre += " du " + date1 + " au " + date2; titre += " (" + cs.getSomme() + " tmoignages)"; sheet.createRow(0).createCell(0).setCellValue(titre); sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) 12 //last column (0-based) )); for (int i = 1; i <= 20; i++) { sheet.createRow(i); } CellStyle redBackGround = wb.createCellStyle(); redBackGround.setFillBackgroundColor(IndexedColors.RED.getIndex()); redBackGround.setFillPattern(CellStyle.BIG_SPOTS); for (UTMS utm : cs.carte.keySet()) { int xy[] = UTMtoXY.convert10x10(utm.utm); Row row = sheet.getRow(xy[1] + 1); Cell cell = row.createCell(xy[0]); int nombre = cs.carte.get(utm); cell.setCellValue(nombre); if (nombre != 0) cell.setCellStyle(redBackGround); } for (int k = 1; k <= 20; k++) { sheet.autoSizeColumn(k); } }
From source file:functions.excels.exports.ChronologieDUnTemoinExcel.java
License:Apache License
public ChronologieDUnTemoinExcel(Map<String, String> info, ChronologieDUnTemoin cdut) { super();/* ww w .j a v a 2 s .c o m*/ Sheet sheet = wb.createSheet("Chronologie d'un tmoin"); Espece espece = Espece.find.byId(Integer.parseInt(info.get("espece"))); SousGroupe sous_groupe = SousGroupe.find.byId(Integer.parseInt(info.get("sous_groupe"))); Groupe groupe = Groupe.find.byId(Integer.parseInt(info.get("groupe"))); StadeSexe stade_sexe = StadeSexe.find.byId(Integer.parseInt(info.get("stade"))); String maille = info.get("maille"); String temoin = info.get("temoin"); String date1 = info.get("jour1") + "/" + info.get("mois1") + "/" + info.get("annee1"); String date2 = info.get("jour2") + "/" + info.get("mois2") + "/" + info.get("annee2"); String titre = "Chronologie des tmoignages "; if (espece != null) titre += "de " + espece.espece_nom; else if (sous_groupe != null) titre += "de " + sous_groupe; else if (groupe != null) titre += "de " + groupe; if (stade_sexe != null) titre += " au stade " + stade_sexe; if (!maille.equals("")) titre += " dans la maille " + maille; titre += " faits par " + temoin; titre += " du " + date1 + " au " + date2; sheet.createRow(0).createCell(0).setCellValue(titre); sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) 12 //last column (0-based) )); Row rowHead = sheet.createRow(1); rowHead.createCell(0).setCellValue("Fiche ID"); rowHead.createCell(1).setCellValue("UTM"); rowHead.createCell(2).setCellValue("Lieu-dit"); rowHead.createCell(3).setCellValue("Commune"); rowHead.createCell(4).setCellValue("Dp."); rowHead.createCell(5).setCellValue("Date min"); rowHead.createCell(6).setCellValue("Date"); rowHead.createCell(7).setCellValue("Espce"); rowHead.createCell(8).setCellValue("Nombre"); rowHead.createCell(9).setCellValue("Stade/Sexe"); rowHead.createCell(10).setCellValue("Tmoins"); rowHead.createCell(11).setCellValue("Mmo"); rowHead.createCell(12).setCellValue("Groupe"); CellStyle cellStyleDate = wb.createCellStyle(); CreationHelper creationHelper = wb.getCreationHelper(); cellStyleDate.setDataFormat(creationHelper.createDataFormat().getFormat("dd/mm/yyyy")); int i = 2; for (InformationsComplementaires complements : cdut.chronologie) { Row row = sheet.createRow(i); Observation observation = complements.informations_complementaires_observation; Fiche fiche = observation.observation_fiche; row.createCell(0).setCellValue(fiche.fiche_id); row.createCell(1).setCellValue(fiche.fiche_utm.utm); row.createCell(2).setCellValue(fiche.fiche_lieudit); if (fiche.fiche_commune != null) { row.createCell(3).setCellValue(fiche.fiche_commune.ville_nom_aer); row.createCell(4).setCellValue(fiche.fiche_commune.ville_departement.departement_code); } if (fiche.fiche_date_min != null) { Cell cell = row.createCell(5); cell.setCellValue(fiche.fiche_date_min.getTime()); cell.setCellStyle(cellStyleDate); } Cell cell = row.createCell(6); cell.setCellValue(fiche.fiche_date.getTime()); cell.setCellStyle(cellStyleDate); row.createCell(7).setCellValue(observation.observation_espece.espece_nom); Integer nombre = complements.informations_complementaires_nombre_de_specimens; if (nombre == null) row.createCell(8).setCellValue("?"); else row.createCell(8).setCellValue(nombre); row.createCell(9).setCellValue(complements.informations_complementaires_stade_sexe.stade_sexe_intitule); StringBuilder membres = new StringBuilder(); List<FicheHasMembre> fhms = fiche.getFicheHasMembre(); for (int j = 0; j < fhms.size() - 1; j++) { membres.append(fhms.get(j).membre); membres.append(", "); } if (!fhms.isEmpty()) membres.append(fhms.get(fhms.size() - 1).membre); else membres.append("et al."); row.createCell(10).setCellValue(membres.toString()); row.createCell(11).setCellValue(fiche.fiche_memo); row.createCell(12) .setCellValue(observation.observation_espece.espece_sous_groupe.sous_groupe_groupe.groupe_nom); i++; } for (int j = 0; j < 11; j++) sheet.autoSizeColumn(j); }
From source file:functions.excels.exports.HistogrammeDesImagosExcel.java
License:Apache License
public HistogrammeDesImagosExcel(Map<String, String> info, HistogrammeDesImagos hdi) throws IOException { super();/* www. ja va 2s . com*/ Sheet sheet = wb.createSheet("Histogramme des imagos"); Espece espece = Espece.find.byId(Integer.parseInt(info.get("espece"))); SousGroupe sous_groupe = SousGroupe.find.byId(Integer.parseInt(info.get("sous_groupe"))); Groupe groupe = Groupe.find.byId(Integer.parseInt(info.get("groupe"))); String maille = info.get("maille"); String date1 = info.get("jour1") + "/" + info.get("mois1") + "/" + info.get("annee1"); String date2 = info.get("jour2") + "/" + info.get("mois2") + "/" + info.get("annee2"); String titre = "Diagramme reprsentant les imagos en fonction de la priode de l'anne "; if (espece != null) titre += "de " + espece.espece_nom; else if (sous_groupe != null) titre += "de " + sous_groupe; else if (groupe != null) titre += "de " + groupe; if (!maille.equals("")) titre += " dans la maille " + maille; titre += " du " + date1 + " au " + date2; titre += " (" + hdi.getSomme() + " tmoignages)"; sheet.createRow(0).createCell(0).setCellValue(titre); sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) 12 //last column (0-based) )); Row row = sheet.createRow(1); row.createCell(0).setCellValue("Priode"); row.createCell(1).setCellValue("Nbr. Obs."); int i = 0; while (i < hdi.histogramme.length) { row = sheet.createRow(i + 2); row.createCell(0); row.createCell(1); sheet.getRow(i + 2).getCell(0).setCellValue(hdi.legende.get(i)); sheet.getRow(i + 2).getCell(1).setCellValue(hdi.histogramme[i]); i++; } sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); }