本文整理汇总了Java中org.apache.poi.ss.util.CellRangeAddress.getLastColumn方法的典型用法代码示例。如果您正苦于以下问题:Java CellRangeAddress.getLastColumn方法的具体用法?Java CellRangeAddress.getLastColumn怎么用?Java CellRangeAddress.getLastColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.util.CellRangeAddress
的用法示例。
在下文中一共展示了CellRangeAddress.getLastColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMergerCellRegionRow
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的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;
}
示例2: getSpan
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
private Span getSpan(XSSFSheet 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);
}
示例3: isMergedRegion
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
private boolean isMergedRegion(XSSFSheet 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;
}
示例4: getMergerCellRegionCol
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的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;
}
示例5: getSpan
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的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);
}
示例6: isMergedRegion
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的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;
}
示例7: copyRow
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
/**
* @param srcSheet the sheet to copy.
* @param destSheet the sheet to create.
* @param srcRow the row to copy.
* @param destRow the row to create.
* @param styleMap -
*/
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, XSSFRow srcRow, XSSFRow destRow, Map<Integer, XSSFCellStyle> styleMap) {
// manage a list of merged zone in order to not insert two times a merged zone
Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
destRow.setHeight(srcRow.getHeight());
// pour chaque row
for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
if(j<0){
}else{
XSSFCell oldCell = srcRow.getCell(j); // ancienne cell
XSSFCell newCell = destRow.getCell(j); // new cell
if (oldCell != null) {
if (newCell == null) {
newCell = destRow.createCell(j);
}
// copy chaque cell
copyCell(oldCell, newCell, styleMap);
// copy les informations de fusion entre les cellules
//System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());
CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());
if (mergedRegion != null) {
//System.out.println("Selected merged region: " + mergedRegion.toString());
CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
//System.out.println("New merged region: " + newMergedRegion.toString());
CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
if (isNewMergedRegion(wrapper, mergedRegions)) {
mergedRegions.add(wrapper);
destSheet.addMergedRegion(wrapper.range);
}
}
}
}
}
}
示例8: getMergedRegionValue
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
/**
* 获取合并单元格的值
* @param sheet
* @param row
* @param column
* @return
*/
public static String getMergedRegionValue(Sheet sheet, int row, int column) {
int sheetMergeCount = sheet.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
CellRangeAddress ca = sheet.getMergedRegion(i);
int firstColumn = ca.getFirstColumn();
int lastColumn = ca.getLastColumn();
int firstRow = ca.getFirstRow();
int lastRow = ca.getLastRow();
if (row >= firstRow && row <= lastRow) {
if (column >= firstColumn && column <= lastColumn) {
Row fRow = sheet.getRow(firstRow);
Cell fCell = fRow.getCell(firstColumn);
return getCellValue(fCell);
}
}
}
return null;
}
示例9: isMergedRegion
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
/**
* 判断指定的单元格是否是合并单元格
* @param sheet
* @param row
* @param column
* @return
*/
public static boolean isMergedRegion(Sheet sheet, int row, int column) {
int sheetMergeCount = sheet.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
CellRangeAddress ca = sheet.getMergedRegion(i);
int firstColumn = ca.getFirstColumn();
int lastColumn = ca.getLastColumn();
int firstRow = ca.getFirstRow();
int lastRow = ca.getLastRow();
if (row >= firstRow && row <= lastRow) {
if (column >= firstColumn && column <= lastColumn) {
return true;
}
}
}
return false;
}
示例10: resizeMergedColumns
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
/**
* Redimensionne les colonnes qui contiennent des régions fusionnées.
*
* Dans POI, les régions fusionnées ne sont pas prises en compte dans le autoSizeColumn.
* Quand on fusionne des cellules sur une même colonne, on corrige la taille de cette colonne si nécessaire.
*
* @param sheet feuille de calcul
* @param columns map contenant l'en-tête et les informations d'une colonne
*/
protected void resizeMergedColumns(Sheet sheet, Collection<ColumnInformation> columns) {
if (sheet.getNumMergedRegions() > 0) {
List<ColumnInformation> columnsInfo = new ArrayList<ColumnInformation>(columns);
for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
if (mergedRegion.getFirstColumn() == mergedRegion.getLastColumn()) {
int columnIndex = mergedRegion.getFirstColumn();
String headerText = getColumnLabel(columnsInfo.get(columnIndex).getHeaderKey());
int headerSize = (int) (headerText.length() * 300 * COLUMN_RESIZE_RATIO);
if (sheet.getColumnWidth(columnIndex) < headerSize) {
sheet.setColumnWidth(columnIndex, headerSize);
}
}
}
}
}
示例11: A1RangeAddress
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
protected A1RangeAddress(String a1address) {
this.addresses = new LinkedList<>();
if (!a1address.contains(RANGE_DELIMITER)) { this.addresses.add(A1Address.fromA1Address(a1address)); return; }
CellRangeAddress addrs = CellRangeAddress.valueOf(a1address);
int fromR = addrs.getFirstRow();
int fromC = addrs.getFirstColumn();
int toR = addrs.getLastRow();
int toC = addrs.getLastColumn();
for (int row = fromR; row <= toR; row++) {
for (int col = fromC; col <= toC; col++) {
this.addresses.add(A1Address.fromRowColumn(row, col));
}
}
}
示例12: generateRow2
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
protected Row generateRow2(ForeachRowInfo repeateRow, final ExcelTemplateValueProvider provider, int rownumb){
Row endRow = repeateRow.getRow().getSheet().createRow(rownumb);
endRow.setHeight(repeateRow.getRow().getHeight());
for(Cell cell : repeateRow.getRow()){
Cell newCell = endRow.createCell(cell.getColumnIndex());
ExcelUtils.copyCellStyle(cell, newCell);
Object newCellValue = provider.parseCellValue(cell, provider);
ExcelUtils.setCellValue(newCell, newCellValue);
CellRangeAddress cr = provider.getCellRange(repeateRow, cell);
if(cr!=null){
CellRangeAddress newCr = new CellRangeAddress(rownumb,
rownumb+(cr.getLastRow()-cr.getFirstRow()),
cr.getFirstColumn(), cr.getLastColumn());
endRow.getSheet().addMergedRegion(newCr);
}
}
return endRow;
}
示例13: removeRegion
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
/**
* 対象の行、列番号が結合されている場合は結合を解除する
*
* @param sheet
* @param removeRowNum
* @param removeColNum
*/
private void removeRegion( Sheet sheet, int removeRowNum, int removeColNum) {
// シート内の結合情報の数だけループする
for ( int i = 0; i < sheet.getNumMergedRegions(); i++) {
// 結合情報(Region)を取得する
CellRangeAddress region = sheet.getMergedRegion( i);
if ( removeRowNum != -1) {
if ( region.getFirstRow() > removeRowNum || removeRowNum > region.getLastRow()) {
continue;
}
}
if ( removeColNum != -1) {
if ( region.getFirstColumn() > removeColNum || removeColNum > region.getLastColumn()) {
continue;
}
}
// 引数の結合INDEXに該当する結合を解除する
sheet.removeMergedRegion( i);
return;
}
}
示例14: validateCellRange
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
protected void validateCellRange(Matcher matcher, Cell cell) {
int desiredR1 = Integer.parseInt( matcher.group(1) );
int desiredC1 = Integer.parseInt( matcher.group(2) );
int desiredR2 = Integer.parseInt( matcher.group(3) );
int desiredC2 = Integer.parseInt( matcher.group(4) );
int actualR1 = cell.getRowIndex() + 1;
int actualC1 = cell.getColumnIndex() + 1;
int actualR2 = actualR1;
int actualC2 = actualC1;
for( int i = 0; i < cell.getSheet().getNumMergedRegions(); ++i) {
CellRangeAddress cra = cell.getSheet().getMergedRegion(i);
if( ( cra.getFirstRow() == cell.getRowIndex() ) && ( cra.getFirstColumn() == cell.getColumnIndex() ) ) {
assertEquals( actualR1, actualR2 );
assertEquals( actualC1, actualC2 );
actualR2 = cra.getLastRow() + 1;
actualC2 = cra.getLastColumn() + 1;
}
}
assertEquals( desiredR1, actualR1 );
assertEquals( desiredC1, actualC1 );
assertEquals( desiredR2, actualR2 );
assertEquals( desiredC2, actualC2 );
}
示例15: setFormRegionStyle
import org.apache.poi.ss.util.CellRangeAddress; //导入方法依赖的package包/类
private void setFormRegionStyle(Sheet sheet, CellRangeAddress ca, CellStyle cs) {
for (int i = ca.getFirstRow(); i <= ca.getLastRow(); i++) {
Row row = CellUtil.getRow(i, sheet);
for (int j = ca.getFirstColumn(); j <= ca.getLastColumn(); j++) {
Cell cell = CellUtil.getCell(row, j);
cell.setCellStyle(cs);
}
}
}