Java Code Examples for org.apache.poi.hssf.usermodel.HSSFSheet#getMergedRegion()
The following examples show how to use
org.apache.poi.hssf.usermodel.HSSFSheet#getMergedRegion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OfficeConverter.java From BBSSDK-for-Android with Apache License 2.0 | 6 votes |
/** * 判断单元格在不在合并单元格范围内,如果是,获取其合并的列数。 */ private static int getMergerCellRegionCol(HSSFSheet sheet, int cellRow, int cellCol) throws Throwable { int retVal = 0; int sheetMergerCount = sheet.getNumMergedRegions(); for (int i = 0; i < sheetMergerCount; i++) { CellRangeAddress cra = sheet.getMergedRegion(i); int firstRow = cra.getFirstRow(); // 合并单元格CELL起始行 int firstCol = cra.getFirstColumn(); // 合并单元格CELL起始列 int lastRow = cra.getLastRow(); // 合并单元格CELL结束行 int lastCol = cra.getLastColumn(); // 合并单元格CELL结束列 if (cellRow >= firstRow && cellRow <= lastRow) { // 判断该单元格是否是在合并单元格中 if (cellCol >= firstCol && cellCol <= lastCol) { retVal = lastCol - firstCol + 1; // 得到合并的列数 break; } } } return retVal; }
Example 2
Source File: OfficeConverter.java From BBSSDK-for-Android with Apache License 2.0 | 6 votes |
/** * 判断单元格是否是合并的单格,如果是,获取其合并的行数。 */ private static int getMergerCellRegionRow(HSSFSheet sheet, int cellRow, int cellCol) throws Throwable { int retVal = 0; int sheetMergerCount = sheet.getNumMergedRegions(); for (int i = 0; i < sheetMergerCount; i++) { CellRangeAddress cra = sheet.getMergedRegion(i); int firstRow = cra.getFirstRow(); // 合并单元格CELL起始行 int firstCol = cra.getFirstColumn(); // 合并单元格CELL起始列 int lastRow = cra.getLastRow(); // 合并单元格CELL结束行 int lastCol = cra.getLastColumn(); // 合并单元格CELL结束列 if (cellRow >= firstRow && cellRow <= lastRow) { // 判断该单元格是否是在合并单元格中 if (cellCol >= firstCol && cellCol <= lastCol) { retVal = lastRow - firstRow + 1; // 得到合并的行数 break; } } } return retVal; }
Example 3
Source File: HSSFExcelParser.java From ureport with Apache License 2.0 | 6 votes |
private Span getSpan(HSSFSheet sheet,int row ,int column){ int sheetMergeCount = sheet.getNumMergedRegions(); for (int i = 0; i < sheetMergeCount; i++) { CellRangeAddress range = sheet.getMergedRegion(i); int firstColumn = range.getFirstColumn(); int lastColumn = range.getLastColumn(); int firstRow = range.getFirstRow(); if(row == firstRow && column==firstColumn){ int lastRow = range.getLastRow(); int rowSpan=lastRow-firstRow; if(rowSpan>0){ rowSpan++; } int colSpan=lastColumn-firstColumn; if(colSpan>0){ colSpan++; } return new Span(rowSpan,colSpan); } } return new Span(0,0); }
Example 4
Source File: HSSFExcelParser.java From ureport with Apache License 2.0 | 6 votes |
private boolean isMergedRegion(HSSFSheet sheet, int row, int column) { int sheetMergeCount = sheet.getNumMergedRegions(); for (int i = 0; i < sheetMergeCount; i++) { CellRangeAddress range = sheet.getMergedRegion(i); int firstColumn = range.getFirstColumn(); int lastColumn = range.getLastColumn(); int firstRow = range.getFirstRow(); int lastRow = range.getLastRow(); if (row > firstRow && row < lastRow) { if (column > firstColumn && column < lastColumn) { return true; } } } return false; }
Example 5
Source File: POIUtils.java From ermasterr with Apache License 2.0 | 6 votes |
public static CellRangeAddress getMergedRegion(final HSSFSheet sheet, final CellLocation location) { for (int i = 0; i < sheet.getNumMergedRegions(); i++) { final CellRangeAddress region = sheet.getMergedRegion(i); final int rowFrom = region.getFirstRow(); final int rowTo = region.getLastRow(); if (rowFrom == location.r && rowTo == location.r) { final int colFrom = region.getFirstColumn(); if (colFrom == location.c) { return region; } } } return null; }
Example 6
Source File: POIUtils.java From ermasterr with Apache License 2.0 | 6 votes |
public static List<CellRangeAddress> getMergedRegionList(final HSSFSheet sheet, final int rowNum) { final List<CellRangeAddress> regionList = new ArrayList<CellRangeAddress>(); for (int i = 0; i < sheet.getNumMergedRegions(); i++) { final CellRangeAddress region = sheet.getMergedRegion(i); final int rowFrom = region.getFirstRow(); final int rowTo = region.getLastRow(); if (rowFrom == rowNum && rowTo == rowNum) { regionList.add(region); } } return regionList; }
Example 7
Source File: POIUtils.java From ermaster-b with Apache License 2.0 | 6 votes |
/** * location�Ŏw�肵���s�́A�������ꂽ�̈�̈ꗗ���擾���܂� * * @param sheet * @param location * @return */ public static List<CellRangeAddress> getMergedRegionList(HSSFSheet sheet, int rowNum) { List<CellRangeAddress> regionList = new ArrayList<CellRangeAddress>(); for (int i = 0; i < sheet.getNumMergedRegions(); i++) { CellRangeAddress region = sheet.getMergedRegion(i); int rowFrom = region.getFirstRow(); int rowTo = region.getLastRow(); if (rowFrom == rowNum && rowTo == rowNum) { regionList.add(region); } } return regionList; }
Example 8
Source File: GenerateDoc.java From danyuan-application with Apache License 2.0 | 4 votes |
/** * @方法名 copySheet * @功能 复制sheet * @参数 @param sheetFrom * @参数 @param sheetTo * @参数 @return * @返回 HSSFSheet * @author Administrator * @throws */ @SuppressWarnings("deprecation") private static HSSFSheet copySheet(HSSFSheet sheetFrom, HSSFSheet sheetTo) { // 初期化 CellRangeAddress region = null; Row rowFrom = null; Row rowTo = null; Cell cellFrom = null; Cell cellTo = null; // セル結合のコピー for (int i = 0; i < sheetFrom.getNumMergedRegions(); i++) { region = sheetFrom.getMergedRegion(i); if ((region.getFirstColumn() >= sheetFrom.getFirstRowNum()) && (region.getLastRow() <= sheetFrom.getLastRowNum())) { sheetTo.addMergedRegion(region); } } // セルのコピー for (int intRow = sheetFrom.getFirstRowNum(); intRow <= sheetFrom.getLastRowNum(); intRow++) { rowFrom = sheetFrom.getRow(intRow); rowTo = sheetTo.createRow(intRow); if (null == rowFrom) { continue; } rowTo.setHeight(rowFrom.getHeight()); for (int intCol = 0; intCol < rowFrom.getLastCellNum(); intCol++) { // セル幅のコピー sheetTo.setDefaultColumnStyle(intCol, sheetFrom.getColumnStyle(intCol)); sheetTo.setColumnWidth(intCol, sheetFrom.getColumnWidth(intCol)); cellFrom = rowFrom.getCell(intCol); cellTo = rowTo.createCell(intCol); if (null == cellFrom) { continue; } // セルスタイルとタイプのコピー cellTo.setCellStyle(cellFrom.getCellStyle()); cellTo.setCellType(cellFrom.getCellType()); // タイトル内容のコピー // 不同数据类型处理 int cellFromType = cellFrom.getCellType(); cellTo.setCellType(cellFromType); if (cellFromType == HSSFCell.CELL_TYPE_NUMERIC) { if (HSSFDateUtil.isCellDateFormatted(cellFrom)) { cellTo.setCellValue(cellFrom.getDateCellValue()); } else { cellTo.setCellValue(cellFrom.getNumericCellValue()); } } else if (cellFromType == HSSFCell.CELL_TYPE_STRING) { cellTo.setCellValue(cellFrom.getRichStringCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_BLANK) { // nothing21 } else if (cellFromType == HSSFCell.CELL_TYPE_BOOLEAN) { cellTo.setCellValue(cellFrom.getBooleanCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_ERROR) { cellTo.setCellErrorValue(cellFrom.getErrorCellValue()); } else if (cellFromType == HSSFCell.CELL_TYPE_FORMULA) { cellTo.setCellFormula(cellFrom.getCellFormula()); } else { // nothing29 } } } // 枠線の設定 sheetTo.setDisplayGridlines(false); // sheetTo.setDisplayGuts(true); // sheetTo.setDisplayRowColHeadings(true); // 剪切 // sheetTo.shiftRows(13, 15, 31, false, false, false); // Excelのズーム設定 sheetTo.setZoom(85, 100); // シートを戻る。 return sheetTo; }
Example 9
Source File: Util.java From Knowage-Server with GNU Affero General Public License v3.0 | 3 votes |
/** * * @param source * the sheet containing the data. * @param rowNum * the num of the row to copy. * @param cellNum * the num of the cell to copy. * @return the CellRangeAddress created. */ public static CellRangeAddress getMergedRegion(HSSFSheet source, int rowNum, short cellNum) { for (int i = 0; i < source.getNumMergedRegions(); i++) { CellRangeAddress merged = source.getMergedRegion(i); if (merged.isInRange(rowNum, cellNum)) { return merged; } } return null; }