當前位置: 首頁>>代碼示例>>Java>>正文


Java CellRangeAddress類代碼示例

本文整理匯總了Java中org.apache.poi.ss.util.CellRangeAddress的典型用法代碼示例。如果您正苦於以下問題:Java CellRangeAddress類的具體用法?Java CellRangeAddress怎麽用?Java CellRangeAddress使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CellRangeAddress類屬於org.apache.poi.ss.util包,在下文中一共展示了CellRangeAddress類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupTotalCell

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
protected void setupTotalCell(Cell cell, final String propId, final int currentRow, final int startRow, int col) {
    cell.setCellStyle(getCellStyle(propId, currentRow, startRow, col, true));
    final HorizontalAlignment poiAlignment = getGridHolder().getCellAlignment(propId);
    CellUtil.setAlignment(cell, poiAlignment);
    Class<?> propType = getGridHolder().getPropertyType(propId);
    if (isNumeric(propType)) {
        CellRangeAddress cra = new CellRangeAddress(startRow, currentRow - 1, col, col);
        if (isHierarchical()) {
            // 9 & 109 are for sum. 9 means include hidden cells, 109 means exclude.
            // this will show the wrong value if the user expands an outlined category, so
            // we will range value it first
            cell.setCellFormula("SUM(" + cra.formatAsString(hierarchicalTotalsSheet.getSheetName(),
                    true) + ")");
        } else {
            cell.setCellFormula("SUM(" + cra.formatAsString() + ")");
        }
    } else {
        if (0 == col) {
            cell.setCellValue(createHelper.createRichTextString("Total"));
        }
    }
}
 
開發者ID:TFyre,項目名稱:vaadin-gridexport,代碼行數:23,代碼來源:ExcelExport.java

示例2: 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;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:17,代碼來源:XSSFExcelParser.java

示例3: 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;
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:22,代碼來源:OfficeConverter.java

示例4: setRegionBorder

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
/**
 * 獲取合並單元格式
 *
 * @param sheet
 * @param row
 * @param columnFrom
 * @param columnTo
 * @return
 */
private static void setRegionBorder(HSSFSheet sheet, int row, int columnFrom, int columnTo) {
    CellRangeAddress region = new CellRangeAddress(row, row, columnFrom, columnTo);
    sheet.addMergedRegion(region);
    final short border = CellStyle.BORDER_THIN;
    HSSFWorkbook wb = sheet.getWorkbook();
    RegionUtil.setBorderBottom(border, region, sheet, wb);
    RegionUtil.setBorderTop(border, region, sheet, wb);
    RegionUtil.setBorderLeft(border, region, sheet, wb);
    RegionUtil.setBorderRight(border, region, sheet, wb);
    RegionUtil.setBottomBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
    RegionUtil.setTopBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
    RegionUtil.setLeftBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
    RegionUtil.setRightBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:24,代碼來源:FileUtil.java

示例5: mergeRows

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
/**
 * 合並行
 */
//TODO 暫時支持兩行表頭
private void mergeRows(Sheet sheet, CellStyle cellStyle, ExcelMeta excelMeta) {

    Row row = null;
    Cell cell = null;
    String[] lastRowVals = new String[excelMeta.getTitleColumnNum()];
    for (int r = 0; r < excelMeta.getTitleRowNum(); r++) {
        for (int c = 0; c < excelMeta.getTitleColumnNum(); c++) {
            row = sheet.getRow(r);
            cell = row.getCell(c);
            if (r == 0) {
                lastRowVals[c] = cell.getStringCellValue();
            } else {
                if (StringUtils.equals(lastRowVals[c], cell.getStringCellValue())) {
                    cell.setCellValue("");
                    sheet.addMergedRegion(new CellRangeAddress(0, r, c, c));
                    Cell nowCell = sheet.getRow(0).getCell(c);
                    nowCell.setCellStyle(cellStyle);
                }
            }

        }
    }

}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:29,代碼來源:ExcelWriter.java

示例6: 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);
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:23,代碼來源:XSSFExcelParser.java

示例7: getStringRangeValue

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
public String getStringRangeValue(Cell cell) {
    int rowIndex = cell.getRowIndex();
    int columnIndex = cell.getColumnIndex();

    Sheet sheet = cell.getSheet();
    int size = sheet.getNumMergedRegions();
    for (int i = 0; i < size; i++) {
        CellRangeAddress range = sheet.getMergedRegion(i);
        if (range.isInRange(rowIndex, columnIndex)) {
            Cell firstCell = getCell(sheet, range.getFirstRow(),
                    range.getFirstColumn()); // 左上のセルを取得
            return getStringValue(firstCell);
        }
    }
    return null;
}
 
開發者ID:cccties,項目名稱:chilo-producer,代碼行數:17,代碼來源:ExcelReader.java

示例8: 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;
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:22,代碼來源:OfficeConverter.java

示例9: formatCellStatus

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
protected void formatCellStatus(Sheet sheet, Cell cell) {
	cell.setCellStyle(styles.get("status"));
	SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
	ConditionalFormattingRule ruleGreen = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "1");
	PatternFormatting fill1 = ruleGreen.createPatternFormatting();
	fill1.setFillBackgroundColor(IndexedColors.GREEN.index);
	fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
	//
	ConditionalFormattingRule ruleRed = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "0");
	PatternFormatting fill2 = ruleRed.createPatternFormatting();
	fill2.setFillBackgroundColor(IndexedColors.RED.index);
	fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
	//
	ConditionalFormattingRule ruleOrange = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "2");
	PatternFormatting fill3 = ruleOrange.createPatternFormatting();
	fill3.setFillBackgroundColor(IndexedColors.ORANGE.index);
	fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
	//
	String name = CellReference.convertNumToColString(cell.getColumnIndex());
	String location = "$" + name + "$" + cell.getRowIndex() + ":$" + name + "$" + (cell.getRowIndex() + 1);

	CellRangeAddress[] regions = { CellRangeAddress.valueOf(location) };
	ConditionalFormattingRule[] cfRules = new ConditionalFormattingRule[] { ruleGreen, ruleRed, ruleOrange };
	sheetCF.addConditionalFormatting(regions, cfRules);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:26,代碼來源:XLTest.java

示例10: createFilter

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
private void createFilter(Sheet sheet) {
	int startRow = ROW_INDEX_COLUMNS_DESCRIPTIONS;
	int lastRow = ROW_INDEX_COLUMNS_DESCRIPTIONS + 1;
	int startCol = 0;
	int lastCol = sheet.getRow(startRow).getLastCellNum() - 1;
	sheet.setAutoFilter(new CellRangeAddress(startRow, lastRow, startCol, lastCol));

}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:9,代碼來源:XLTestSummarySheet.java

示例11: addMergedRegions

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
/**
 * 合並單元格
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-06-21
 * @version     v1.0
 *
 * @param i_Sheet        工作表
 * @param i_FirstRow     首行
 * @param i_LastRow      尾行
 * @param i_FirstColumn  首列
 * @param i_LastColumn   尾列
 * @param i_IsSafe       是要安全?還是要性能
 */
public final static void addMergedRegions(Sheet i_Sheet ,int i_FirstRow ,int i_LastRow ,int i_FirstColumn ,int i_LastColumn ,boolean i_IsSafe)
{
    if ( i_FirstRow == i_LastRow && i_FirstColumn == i_LastColumn )
    {
        return;
    }
    
    CellRangeAddress v_CellRA = new CellRangeAddress(i_FirstRow 
                                                    ,i_LastRow 
                                                    ,i_FirstColumn
                                                    ,i_LastColumn);
    
    if ( i_IsSafe )
    {
        i_Sheet.addMergedRegion(v_CellRA);
    }
    else
    {
        i_Sheet.addMergedRegionUnsafe(v_CellRA);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:36,代碼來源:ExcelHelp.java

示例12: 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);
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:23,代碼來源:HSSFExcelParser.java

示例13: 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;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:17,代碼來源:HSSFExcelParser.java

示例14: addTitleToSheet

import org.apache.poi.ss.util.CellRangeAddress; //導入依賴的package包/類
public int addTitleToSheet(ReportTitle reportTitle, Sheet sheet, int row, int firstCol, int lastCol) {
	if (!reportTitle.isShowTitle()) {
		return row;
	}
	Row titleRow = sheet.createRow(row);
	Cell titleCell = titleRow.createCell(firstCol);
	titleCell.setCellType(Cell.CELL_TYPE_STRING);
	titleCell.setCellValue(reportTitle.getTitle());
	CellStyle titleStyle = new TitleStyleBuilder().builder(reportTitle, sheet.getWorkbook());
	titleCell.setCellStyle(titleStyle);
	CellRangeAddress rangle = new CellRangeAddress(row, row, firstCol, lastCol);
	sheet.addMergedRegion(rangle);
	this.setCellRangeAddressBorder(rangle, sheet);
	return row + 1;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:16,代碼來源:ExcelReportBuilder.java

示例15: 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);
                }
            }
        }
        }
        
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:44,代碼來源:Util.java


注:本文中的org.apache.poi.ss.util.CellRangeAddress類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。