本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getNumMergedRegions方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFSheet.getNumMergedRegions方法的具体用法?Java HSSFSheet.getNumMergedRegions怎么用?Java HSSFSheet.getNumMergedRegions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.getNumMergedRegions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMergerCellRegionCol
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 判断单元格在不在合并单元格范围内,如果是,获取其合并的列数。
*/
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;
}
示例2: getMergerCellRegionRow
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 判断单元格是否是合并的单格,如果是,获取其合并的行数。
*/
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;
}
示例3: getSpan
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
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);
}
示例4: getMergedRegion
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
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;
}
示例5: getMergedRegionList
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
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;
}
示例6: getMergedRegion
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public static CellRangeAddress getMergedRegion(HSSFSheet sheet,
CellLocation location) {
for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
CellRangeAddress region = sheet.getMergedRegion(i);
int rowFrom = region.getFirstRow();
int rowTo = region.getLastRow();
if (rowFrom == location.r && rowTo == location.r) {
int colFrom = region.getFirstColumn();
if (colFrom == location.c) {
return region;
}
}
}
return null;
}
示例7: getMergedRegionList
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
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;
}
示例8: isMergedRegion
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
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;
}
示例9: getMergedRegion
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* Récupère les informations de fusion des cellules dans la sheet source
* pour les appliquer à la sheet destination... Récupère toutes les zones
* merged dans la sheet source et regarde pour chacune d'elle si elle se
* trouve dans la current row que nous traitons. Si oui, retourne l'objet
* CellRangeAddress.
*
* @param sheet 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 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;
}
}
return null;
}