List of usage examples for org.apache.poi.ss.usermodel Row getHeightInPoints
float getHeightInPoints();
From source file:net.sf.excelutils.WorkbookUtils.java
License:Apache License
/** * copy row//from w w w. j a v a 2s .com * * @param sheet * @param from begin of the row * @param to destination fo the row * @param count count of copy */ public static void copyRow(Sheet sheet, int from, int to, int count) { for (int rownum = from; rownum < from + count; rownum++) { Row fromRow = sheet.getRow(rownum); Row toRow = getRow(to + rownum - from, sheet); if (null == fromRow) return; toRow.setHeight(fromRow.getHeight()); toRow.setHeightInPoints(fromRow.getHeightInPoints()); int lastCellNum = fromRow.getLastCellNum(); lastCellNum = lastCellNum > 255 ? 255 : lastCellNum; for (int i = fromRow.getFirstCellNum(); i <= lastCellNum && i >= 0; i++) { Cell fromCell = getCell(fromRow, i); Cell toCell = getCell(toRow, i); // toCell.setEncoding(fromCell.getEncoding()); toCell.setCellStyle(fromCell.getCellStyle()); toCell.setCellType(fromCell.getCellType()); switch (fromCell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: toCell.setCellValue(fromCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_FORMULA: toCell.setCellFormula(fromCell.getCellFormula()); break; case Cell.CELL_TYPE_NUMERIC: toCell.setCellValue(fromCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: toCell.setCellValue(fromCell.getStringCellValue()); break; default: } } } // copy merged region List shiftedRegions = new ArrayList(); for (int i = 0; i < sheet.getNumMergedRegions(); i++) { CellRangeAddress r = sheet.getMergedRegion(i); if (r.getFirstRow() >= from && r.getLastRow() < from + count) { CellRangeAddress n_r = new CellRangeAddress(r.getFirstRow() + to - from, r.getLastRow() + to - from, r.getFirstColumn(), r.getLastColumn()); shiftedRegions.add(n_r); } } // readd so it doesn't get shifted again Iterator iterator = shiftedRegions.iterator(); while (iterator.hasNext()) { CellRangeAddress region = (CellRangeAddress) iterator.next(); sheet.addMergedRegion(region); } }
From source file:org.bbreak.excella.reports.util.ReportsUtil.java
License:Open Source License
/** * ??????float[?]????? ???????-1??/* w w w. ja v a2 s. co m*/ * * @param sheet ?? * @param bStartRowIndex ? * @param bEndRowIndex ? * @return ?? */ public static float[] getRowHeight(Sheet sheet, int bStartRowIndex, int bEndRowIndex) { float[] height = new float[bEndRowIndex - bStartRowIndex + 1]; int rowIdx = 0; for (int bRowIndex = bStartRowIndex; bRowIndex <= bEndRowIndex; bRowIndex++) { Row row = sheet.getRow(bRowIndex); if (row == null) { // ?????????? // ???-1? height[rowIdx] = -1; } else { height[rowIdx] = row.getHeightInPoints(); } rowIdx++; } return height; }
From source file:org.bbreak.excella.reports.util.ReportsUtilTest.java
License:Open Source License
/** * {@link org.bbreak.excella.reports.util.ReportsUtil#getRowHeight(org.apache.poi.ss.usermodel.Sheet, int, int)} ???? *///from ww w. j a va2 s. co m @Test public void testGetRowHeight() { Workbook workbook = getWorkbook(); Sheet sheet = workbook.getSheetAt(0); Row row0 = sheet.getRow(0); float[] height = ReportsUtil.getRowHeight(sheet, 0, 19); // ????????? // ???????????? // ?????(getRow(0))??? assertTrue(height[0] > 0); assertEquals(height[0], row0.getHeightInPoints(), 0.01); // ?????????? // ???-1?? // ???????(getRow(19))??? assertEquals(height[19], -1, 0.01); }
From source file:org.bonitasoft.connectors.excel.AddDimensionedImage.java
License:Apache License
/** * Determines whether the sheet's row should be re-sized to accomodate * the image, adjusts the rows height if necessary and creates then * returns a ClientAnchorDetail object that facilitates construction of * a ClientAnchor that will fix the image on the sheet and establish * it's size./* ww w . j av a 2s. c o m*/ * * @param sheet A reference to the sheet that will 'contain' the image. * @param rowNumber A primtive int that contains the index number of a * row on the sheet. * @param reqImageHeightMM A primtive double that contains the required * height of the image in millimetres * @param resizeBehaviour A primitve int whose value will indicate how the * height of the row should be adjusted if the * required height of the image is greater than the * height of the row. * @return An instance of the ClientAnchorDetail class that will contain * the index number of the row containing the cell whose top * left hand corner also defines the top left hand corner of the * image, the index number of the row containing the cell whose * top left hand corner also defines the bottom right hand * corner of the image and an inset that determines how far the * bottom edge of the image can protrude into the next (lower) * row - expressed as a specific number of co-ordinate positions. */ private ClientAnchorDetail fitImageToRows(Sheet sheet, int rowNumber, double reqImageHeightMM, int resizeBehaviour) { Row row = null; double rowHeightMM = 0.0D; double rowCoordinatesPerMM = 0.0D; int pictureHeightCoordinates = 0; ClientAnchorDetail rowClientAnchorDetail = null; // Get the row and it's height row = sheet.getRow(rowNumber); if (row == null) { // Create row if it does not exist. row = sheet.createRow(rowNumber); } // Get the row's height in millimetres rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE; // Check that the row's height will accomodate the image at the required // dimensions. If the height of the row is LESS than the required height // of the image, decide how the application should respond - resize the // row or overlay the image across a series of rows. if (rowHeightMM < reqImageHeightMM) { if ((resizeBehaviour == AddDimensionedImage.EXPAND_ROW) || (resizeBehaviour == AddDimensionedImage.EXPAND_ROW_AND_COLUMN)) { row.setHeightInPoints((float) (reqImageHeightMM * ConvertImageUnits.POINTS_PER_MILLIMETRE)); rowHeightMM = reqImageHeightMM; rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS / rowHeightMM; pictureHeightCoordinates = (int) (reqImageHeightMM * rowCoordinatesPerMM); rowClientAnchorDetail = new ClientAnchorDetail(rowNumber, rowNumber, pictureHeightCoordinates); } // If the user has chosen to overlay both rows and columns or just // to expand ONLY the size of the columns, then calculate how to lay // the image out ver one or more rows. else if ((resizeBehaviour == AddDimensionedImage.OVERLAY_ROW_AND_COLUMN) || (resizeBehaviour == AddDimensionedImage.EXPAND_COLUMN)) { rowClientAnchorDetail = this.calculateRowLocation(sheet, rowNumber, reqImageHeightMM); } } // Else, if the image is smaller than the space available else { rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS / rowHeightMM; pictureHeightCoordinates = (int) (reqImageHeightMM * rowCoordinatesPerMM); rowClientAnchorDetail = new ClientAnchorDetail(rowNumber, rowNumber, pictureHeightCoordinates); } return (rowClientAnchorDetail); }
From source file:org.bonitasoft.connectors.excel.AddDimensionedImage.java
License:Apache License
/** * If the image is to overlie more than one rows, calculations need to be * performed to determine how many rows and whether the image will * overlie just a part of one row in order to be presented at the * required size./*from w w w .j a va 2s. c om*/ * * @param sheet The sheet that will 'contain' the image. * @param startingRow A primitive int whose value is the index of the row * that contains the cell whose top left hand corner * should be aligned with the top left hand corner of * the image. * @param reqImageHeightMM A primitive double whose value will indicate the * required height of the image in millimetres. * @return An instance of the ClientAnchorDetail class that will contain * the index number of the row containing the cell whose top * left hand corner also defines the top left hand corner of the * image, the index number of the row containing the cell whose top * left hand corner also defines the bottom right hand corner of * the image and an inset that determines how far the bottom edge * can protrude into the next (lower) row - expressed as a specific * number of co-ordinate positions. */ private ClientAnchorDetail calculateRowLocation(Sheet sheet, int startingRow, double reqImageHeightMM) { ClientAnchorDetail clientAnchorDetail = null; Row row = null; double rowHeightMM = 0.0D; double totalRowHeightMM = 0.0D; double overlapMM = 0.0D; double rowCoordinatesPerMM = 0.0D; int toRow = startingRow; int inset = 0; // Step through the rows in the sheet and accumulate a total of their // heights. while (totalRowHeightMM < reqImageHeightMM) { row = sheet.getRow(toRow); // Note, if the row does not already exist on the sheet then create // it here. if (row == null) { row = sheet.createRow(toRow); } // Get the row's height in millimetres and add to the running total. rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE; totalRowHeightMM += rowHeightMM; toRow++; } // Owing to the way the loop above works, the rowNumber will have been // incremented one row too far. Undo that here. toRow--; // Check to see whether the image should occupy an exact number of // rows. If so, build the ClientAnchorDetail record to point // to those rows and with an inset of the total number of co-ordinate // position in the row. // // To overcome problems that can occur with comparing double values for // equality, cast both to int(s) to truncate the value; VERY crude and // I do not really like it!! if ((int) totalRowHeightMM == (int) reqImageHeightMM) { clientAnchorDetail = new ClientAnchorDetail(startingRow, toRow, ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS); } else { // Calculate how far the image will project into the next row. Note // that the height of the last row assessed is subtracted from the // total height of all rows assessed so far. overlapMM = reqImageHeightMM - (totalRowHeightMM - rowHeightMM); // To prevent an exception being thrown when the required width of // the image is very close indeed to the column size. if (overlapMM < 0) { overlapMM = 0.0D; } rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS / rowHeightMM; inset = (int) (overlapMM * rowCoordinatesPerMM); clientAnchorDetail = new ClientAnchorDetail(startingRow, toRow, inset); } return (clientAnchorDetail); }
From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java
License:Apache License
private static InnerRow getTemplateRow(Map<Integer, InnerRow> cache, Sheet sheet, ExcelWriteSheetProcessor<?> sheetProcessor, int rowIndex) { InnerRow cachedRow = cache.get(rowIndex); if (cachedRow != null || cache.containsKey(rowIndex)) { return cachedRow; }/*from w w w . j a v a 2 s . c o m*/ InnerRow templateRow = null; if (sheetProcessor.getTemplateStartRowIndex() != null && sheetProcessor.getTemplateEndRowIndex() != null) { if (rowIndex <= sheetProcessor.getTemplateEndRowIndex()) { return null; } int tempRowIndex = (rowIndex - sheetProcessor.getTemplateEndRowIndex() - 1) % (sheetProcessor.getTemplateEndRowIndex() - sheetProcessor.getTemplateStartRowIndex() + 1) + sheetProcessor.getTemplateStartRowIndex(); Row tempRow = sheet.getRow(tempRowIndex); if (tempRow != null) { templateRow = new InnerRow(); templateRow.setHeight(tempRow.getHeight()); templateRow.setHeightInPoints(tempRow.getHeightInPoints()); templateRow.setRowStyle(tempRow.getRowStyle()); templateRow.setZeroHeight(tempRow.getZeroHeight()); for (int i = tempRow.getFirstCellNum(); i <= tempRow.getLastCellNum(); i++) { Cell cell = tempRow.getCell(i); if (cell != null) { InnerCell innerCell = new InnerCell(); innerCell.setCellStyle(cell.getCellStyle()); innerCell.setCellType(cell.getCellType()); templateRow.setCell(i, innerCell); } } } } cache.put(rowIndex, templateRow); return templateRow; }
From source file:org.openflexo.technologyadapter.excel.view.ExcelSheetView.java
License:Open Source License
private void updateRowHeights() { for (Row row : sheet.getSheet()) { table.setRowHeight(row.getRowNum(), (int) row.getHeightInPoints()); }/*from w ww .j a v a2 s .c om*/ }
From source file:org.tiefaces.components.websheet.service.WebSheetLoader.java
License:MIT License
/** * Load header row with configuration tab. * * @param sheetConfig//from w ww . jav a 2 s . com * the sheet config * @param rangeBuildRef * the range build ref * @param currentRow * the current row * @param cellRangeMap * the cell range map * @param skippedRegionCells * the skipped region cells * @return the list */ private List<HeaderCell> loadHeaderRowWithConfigurationTab(final SheetConfiguration sheetConfig, final RangeBuildRef rangeBuildRef, final int currentRow, final Map<String, CellRangeAddress> cellRangeMap, final List<String> skippedRegionCells) { Sheet sheet1 = rangeBuildRef.getSheet(); int left = rangeBuildRef.getLeft(); int right = rangeBuildRef.getRight(); double totalWidth = (double) rangeBuildRef.getTotalWidth(); Row row = sheet1.getRow(currentRow); List<HeaderCell> headercells = new ArrayList<>(); for (int cindex = left; cindex <= right; cindex++) { String cellindex = CellUtility.getCellIndexNumberKey(cindex, currentRow); if (!skippedRegionCells.contains(cellindex) && !sheet1.isColumnHidden(cindex)) { Cell cell = null; if (row != null) { cell = row.getCell(cindex, MissingCellPolicy.CREATE_NULL_AS_BLANK); } int originRowIndex = ConfigurationUtility.getOriginalRowNumInHiddenColumn(row); if (cell != null) { FacesCell fcell = new FacesCell(); CellUtility.convertCell(sheetConfig, fcell, cell, cellRangeMap, originRowIndex, parent.getCellAttributesMap(), null); parent.getPicHelper().setupFacesCellPictureCharts(sheet1, fcell, cell, WebSheetUtility.getFullCellRefName(sheet1, cell)); CellStyleUtility.setupCellStyle(parent.getWb(), fcell, cell, row.getHeightInPoints()); fcell.setColumnStyle(fcell.getColumnStyle() + getColumnWidthStyle(sheet1, cellRangeMap, cellindex, cindex, totalWidth)); fcell.setColumnIndex(cindex); headercells.add(new HeaderCell(Integer.toString(fcell.getRowspan()), Integer.toString(fcell.getColspan()), fcell.getStyle(), fcell.getColumnStyle(), CellUtility.getCellValueWithFormat(cell, parent.getFormulaEvaluator(), parent.getDataFormatter()), true, true)); } } } fillToMaxColumns(headercells); return headercells; }
From source file:org.tiefaces.components.websheet.service.WebSheetLoader.java
License:MIT License
/** * Assemble faces body row.//from w w w. j a va2 s .c o m * * @param rowIndex * the row index * @param sheet1 * the sheet 1 * @param left * the left * @param right * the right * @param sheetConfig * the sheet config * @param cellRangeMap * the cell range map * @param skippedRegionCells * the skipped region cells * @return the faces row */ private FacesRow assembleFacesBodyRow(final int rowIndex, final Sheet sheet1, final int left, final int right, final SheetConfiguration sheetConfig, final Map<String, CellRangeAddress> cellRangeMap, final List<String> skippedRegionCells) { FacesRow facesRow = new FacesRow(rowIndex); Row row = sheet1.getRow(rowIndex); setupRowInfo(facesRow, sheet1, row, rowIndex, CommandUtility.isRowAllowAdd(row, sheetConfig)); String saveAttrList = SaveAttrsUtility.getSaveAttrListFromRow(row); List<FacesCell> bodycells = new ArrayList<>(); for (int cindex = left; cindex <= right; cindex++) { String cellindex = CellUtility.getCellIndexNumberKey(cindex, rowIndex); if (!skippedRegionCells.contains(cellindex) && !sheet1.isColumnHidden(cindex)) { Cell cell = null; if (row != null) { cell = row.getCell(cindex, MissingCellPolicy.CREATE_NULL_AS_BLANK); } if (cell != null) { FacesCell fcell = new FacesCell(); CellUtility.convertCell(sheetConfig, fcell, cell, cellRangeMap, facesRow.getOriginRowIndex(), parent.getCellAttributesMap(), saveAttrList); parent.getPicHelper().setupFacesCellPictureCharts(sheet1, fcell, cell, WebSheetUtility.getFullCellRefName(sheet1, cell)); CellStyleUtility.setupCellStyle(parent.getWb(), fcell, cell, row.getHeightInPoints()); fcell.setColumnIndex(cindex); bodycells.add(fcell); addCache(cell); } else { bodycells.add(null); } } else { bodycells.add(null); } } facesRow.setCells(bodycells); return facesRow; }
From source file:org.tiefaces.components.websheet.utility.PicturesUtility.java
License:MIT License
/** * Gets the anchor size.//from w ww . j a v a 2 s .c o m * * @param sheet1 * the sheet 1 * @param fcell * the fcell * @param cell * the cell * @param anchor * the anchor * @return the anchor size */ public static AnchorSize getAnchorSize(final Sheet sheet1, final FacesCell fcell, final Cell cell, final ClientAnchor anchor) { if (!(sheet1 instanceof XSSFSheet)) { return null; } double picWidth = 0.0; double picHeight = 0.0; int left = anchor.getDx1() / org.apache.poi.util.Units.EMU_PER_PIXEL; int top = (int) ((double) anchor.getDy1() / org.apache.poi.util.Units.EMU_PER_PIXEL / WebSheetUtility.PICTURE_HEIGHT_ADJUST); int right = anchor.getDx2() / org.apache.poi.util.Units.EMU_PER_PIXEL; int bottom = (int) ((double) anchor.getDy2() / org.apache.poi.util.Units.EMU_PER_PIXEL / WebSheetUtility.PICTURE_HEIGHT_ADJUST); double cellWidth = 0.0; double cellHeight = 0.0; if ((cell != null) && (fcell != null)) { for (int col = cell.getColumnIndex(); col < cell.getColumnIndex() + fcell.getColspan(); col++) { cellWidth += sheet1.getColumnWidthInPixels(col); } double lastCellWidth = sheet1.getColumnWidthInPixels(cell.getColumnIndex() + fcell.getColspan() - 1); for (int rowIndex = cell.getRowIndex(); rowIndex < cell.getRowIndex() + fcell.getRowspan(); rowIndex++) { cellHeight += WebSheetUtility.pointsToPixels(sheet1.getRow(rowIndex).getHeightInPoints()); } double lastCellHeight = WebSheetUtility .pointsToPixels(sheet1.getRow(cell.getRowIndex() + fcell.getRowspan() - 1).getHeightInPoints()); picWidth = cellWidth - lastCellWidth + right - left; picHeight = cellHeight - lastCellHeight + bottom - top; } else { for (short col = anchor.getCol1(); col < anchor.getCol2(); col++) { picWidth += sheet1.getColumnWidthInPixels(col); } for (int rowindex = anchor.getRow1(); rowindex < anchor.getRow2(); rowindex++) { Row row = sheet1.getRow(rowindex); if (row != null) { picHeight += WebSheetUtility.pointsToPixels(row.getHeightInPoints()); } } } return new AnchorSize(left, top, (int) picWidth, (int) picHeight, cellWidth, cellHeight); }