Example usage for org.apache.poi.hssf.usermodel HSSFSheet getNumMergedRegions

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getNumMergedRegions

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet getNumMergedRegions.

Prototype

@Override
public int getNumMergedRegions() 

Source Link

Document

returns the number of merged regions

Usage

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static boolean[][] getMergedCells(HSSFSheet sheet) {
    int lastRowNum = sheet.getLastRowNum();
    short maxCellNum = getMaxCellNum(sheet);

    // Compute merged regions
    boolean[][] merged = new boolean[lastRowNum + 1][maxCellNum + 1];
    for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
        Region region = sheet.getMergedRegionAt(i);
        for (int rowNum = region.getRowFrom(); rowNum <= region.getRowTo(); rowNum++) {
            for (int columnNum = region.getColumnFrom(); columnNum <= region.getColumnTo(); columnNum++) {
                if (rowNum != region.getRowFrom() || columnNum != region.getColumnFrom())
                    merged[rowNum][columnNum] = true;
            }/* w  ww .  j  av a  2 s.c om*/
        }
    }

    return merged;
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copySheet(HSSFWorkbook workbook, HSSFSheet destination, HSSFSheet source) {

    // Copy column width
    short maxCellNum = getMaxCellNum(source);
    for (short i = 0; i <= maxCellNum; i++) {
        destination.setColumnWidth(i, source.getColumnWidth(i));
    }//from   w w  w .  ja va 2 s .  c o  m

    // Copy merged cells
    for (int i = 0; i < source.getNumMergedRegions(); i++) {
        Region region = source.getMergedRegionAt(i);
        destination.addMergedRegion(region);
    }

    // Copy rows
    for (int i = 0; i <= source.getLastRowNum(); i++) {
        HSSFRow sourceRow = source.getRow(i);
        HSSFRow destinationRow = destination.createRow(i);
        copyRow(workbook, destinationRow, sourceRow);
    }
}

From source file:ro.nextreports.engine.exporter.util.XlsUtil.java

License:Apache License

public static CellRangeAddress getMergedRegion(HSSFSheet sheet, int rowNum, short cellNum) {
    for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
        CellRangeAddress merged = sheet.getMergedRegion(i);
        if (merged.isInRange(rowNum, cellNum)) {
            return merged;
        }//  w ww . j av a  2  s.c o  m
    }
    return null;
}