• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AreaReference类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.poi.ss.util.AreaReference的典型用法代码示例。如果您正苦于以下问题:Java AreaReference类的具体用法?Java AreaReference怎么用?Java AreaReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AreaReference类属于org.apache.poi.ss.util包,在下文中一共展示了AreaReference类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getReferenceList

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
private List<Object> getReferenceList(XSSFSheet sheet, DataValidationConstraint validationConstraint) {
	List<Object> references = new LinkedList<>();

	AreaReference areaRef = new AreaReference(validationConstraint.getFormula1());
	CellReference[] cellRefs = areaRef.getAllReferencedCells();
	for (CellReference cellRef : cellRefs) {
		XSSFSheet referenceListSheet;
		if (cellRef.getSheetName() != null) {
			referenceListSheet = sheet.getWorkbook().getSheet(cellRef.getSheetName());
		} else {
			referenceListSheet = sheet;
		}
		Row row = referenceListSheet.getRow(cellRef.getRow());
		if (row != null) {
			Cell cell = row.getCell(cellRef.getCol());
			if (cell != null) {
				Object cellValue = CellValueParser.getCellValue(cell);
				references.add(cellValue);
			}
		}
	}
	return references;
}
 
开发者ID:ykaragol,项目名称:poi-data-validation,代码行数:24,代码来源:DataValidator.java


示例2: validateNamedRange

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
private void validateNamedRange( Workbook workbook, int index, String name, int sheetIndex, int row1, int col1, int row2, int col2 ) {

		Name namedRange = workbook.getNameAt(index);
        assertEquals( name,namedRange.getNameName() );
        assertEquals( sheetIndex, namedRange.getSheetIndex() );
        
        AreaReference ref = new AreaReference( namedRange.getRefersToFormula() );
        
        if( ( row1 == row2 ) && ( col1 == col2 ) ) {
        	assertTrue( ref.isSingleCell() );
        	assertEquals( row1, ref.getFirstCell().getRow() );
        	assertEquals( col1, ref.getFirstCell().getCol() );
        } else {
        	assertTrue( AreaReference.isContiguous( namedRange.getRefersToFormula() ) );
	        assertEquals( row1, Math.min( ref.getFirstCell().getRow(), ref.getLastCell().getRow() ) );
	        assertEquals( col1, Math.min( ref.getFirstCell().getCol(), ref.getLastCell().getCol() ) );
	        assertEquals( row2, Math.max( ref.getFirstCell().getRow(), ref.getLastCell().getRow() ) );
	        assertEquals( col2, Math.max( ref.getFirstCell().getCol(), ref.getLastCell().getCol() ) );
        }
	}
 
开发者ID:eclipse,项目名称:birt,代码行数:21,代码来源:HyperlinksTest.java


示例3: defineName

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
/**
 * 指定した範囲の名前を登録する。
 * <p>POI-3.7以上が必要。
 * <p>指定した名前が既に存在する場合は、新しい範囲に書き換える。
 * @param sheet シート
 * @param name 名前
 * @param startPosition 設定するセルの開始位置
 * @param endPosition 設定するセルの終了位置
 * @return
 */
public static Name defineName(final Sheet sheet, final String name,
        final Point startPosition, final Point endPosition) {
    
    ArgUtils.notNull(sheet, "sheet");
    ArgUtils.notEmpty(name, "name");
    ArgUtils.notNull(startPosition, "startPosition");
    ArgUtils.notNull(endPosition, "endPosition");
    
    final Workbook workbook = sheet.getWorkbook();
    Name nameObj = workbook.getName(name);
    if(nameObj == null) {
        nameObj = workbook.createName();
        nameObj.setNameName(name);
    }
    
    final AreaReference areaRef = buildNameArea(sheet.getSheetName(), startPosition, endPosition);
    nameObj.setRefersToFormula(areaRef.formatAsString());
    
    return nameObj;
    
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:32,代码来源:POIUtils.java


示例4: updateFormulas

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
protected void updateFormulas(Area templateArea, Area dependentResultArea) {
    HSSFSheet templateSheet = getTemplateSheetForRangeName(templateWorkbook, templateArea.getName());
    HSSFSheet resultSheet = templateToResultSheetsMapping.get(templateSheet);

    AreaReference area = dependentResultArea.toAreaReference();
    for (CellReference cell : area.getAllReferencedCells()) {
        HSSFCell resultCell = getCellFromReference(cell, resultSheet);

        if (resultCell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
            Ptg[] ptgs = HSSFFormulaParser.parse(resultCell.getCellFormula(), resultWorkbook);

            for (Ptg ptg : ptgs) {
                if (ptg instanceof AreaPtg) {
                    areaDependencyManager.updateAreaPtg(templateArea, dependentResultArea, (AreaPtg) ptg);
                } else if (ptg instanceof RefPtg) {
                    areaDependencyManager.updateRefPtg(templateArea, dependentResultArea, (RefPtg) ptg);
                }
            }

            String calculatedFormula = HSSFFormulaParser.toFormulaString(templateWorkbook, ptgs);
            resultCell.setCellFormula(calculatedFormula);
        }
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:25,代码来源:XLSFormatter.java


示例5: buildNameArea

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
/**
 * 名前の範囲の形式を組み立てる。
 * <code>シート名!$A$1:$A:$5</code>
 * @param sheetName シート名
 * @param startPosition 設定するセルの開始位置
 * @param endPosition 設定するセルの終了位置
 * @return
 */
public static AreaReference buildNameArea(final String sheetName,
        final Point startPosition, final Point endPosition) {
    
    ArgUtils.notEmpty(sheetName, "sheetName");
    ArgUtils.notNull(startPosition, "startPosition");
    ArgUtils.notNull(endPosition, "endPosition");
    
    final CellReference firstRefs = new CellReference(sheetName, startPosition.y, startPosition.x, true, true);
    final CellReference lastRefs = new CellReference(sheetName, endPosition.y, endPosition.x, true, true);
    
    return new AreaReference(firstRefs, lastRefs);
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:21,代码来源:POIUtils.java


示例6: getRangeContent

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public static CellReference[] getRangeContent(HSSFWorkbook workbook, String rangeName) {
    AreaReference areaForRange = getAreaForRange(workbook, rangeName);
    if (areaForRange == null) {
        return null;
    }

    return areaForRange.getAllReferencedCells();
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:9,代码来源:HSSFRangeHelper.java


示例7: getAreaForRange

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public static AreaReference getAreaForRange(HSSFWorkbook workbook, String rangeName) {
    int rangeNameIdx = workbook.getNameIndex(rangeName);
    if (rangeNameIdx == -1) return null;

    HSSFName aNamedRange = workbook.getNameAt(rangeNameIdx);
    return new AreaReference(aNamedRange.getRefersToFormula(), SpreadsheetVersion.EXCEL97);
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:8,代码来源:HSSFRangeHelper.java


示例8: isOverlapped

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public boolean isOverlapped(Name name) {
	String ref = name.getRefersToFormula();
	int idx = ref.indexOf('!');
	if (idx != -1) {
		ref = ref.substring(idx + 1);
	}
	AreaReference area = new AreaReference(ref);
	CellReference topLeft = area.getFirstCell();
	CellReference bottomRight = area.getLastCell();
	CellRangeAddress cra = new CellRangeAddress(
		topLeft.getRow(), bottomRight.getRow(), 
		topLeft.getCol(), bottomRight.getCol()
	);
	return isOverlapped(cra);
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:16,代码来源:InputRule.java


示例9: getNames

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
private List<String> getNames(XSSFWorkbook workbook, CTStrRef strRef) {
	List<String> ret = new ArrayList<String>();
	try {
		CellReference[] cells = new AreaReference(strRef.getF()).getAllReferencedCells();
		Sheet sheet = workbook.getSheet(cells[0].getSheetName());
		if (sheet == null) {
			throw new Exception(strRef.getF());
		}
		int idx = 0;
		NameInfo[] names = new NameInfo[cells.length];
		for (CellReference ref : cells) {
			names[idx++] = new NameInfo(NameInfo.TYPE_NAME, ExcelUtils.pointToName(ref.getCol(), ref.getRow()));
			String str = null;
			Row row = sheet.getRow(ref.getRow());
			if (row != null) {
				Cell cell = row.getCell(ref.getCol());
				if (cell != null) {
					str = cell.getStringCellValue();
				}
			}
			if (str == null) {
				str = "";
			}
			ret.add(str);
		}
		addNameInfo(names);
	} catch (Exception e) {
		e.printStackTrace();
		ret.clear();
		if (strRef.isSetStrCache()) {
			CTStrData data = strRef.getStrCache();
			for (int i=0; i<data.sizeOfPtArray(); i++) {
				CTStrVal pt = data.getPtArray(i);
				ret.add(pt.getV());
			}
		}
	}
	return ret;
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:40,代码来源:Flotr2ChartFactory.java


示例10: getValues

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
private List<Double> getValues(XSSFWorkbook workbook, CTNumRef numRef) {
	List<Double> ret = new ArrayList<Double>();
	try {
		CellReference[] cells = new AreaReference(numRef.getF()).getAllReferencedCells();
		Sheet sheet = workbook.getSheet(cells[0].getSheetName());
		if (sheet == null) {
			throw new Exception(numRef.getF());
		}
		int idx = 0;
		NameInfo[] names = new NameInfo[cells.length];
		for (CellReference ref : cells) {
			names[idx++] = new NameInfo(NameInfo.TYPE_VALUE, ExcelUtils.pointToName(ref.getCol(), ref.getRow()));
			double d = 0.0;
			Row row = sheet.getRow(ref.getRow());
			if (row != null) {
				Cell cell = row.getCell(ref.getCol());
				if (cell != null) {
					d = cell.getNumericCellValue();
				}
			}
			ret.add(d);
		}
		addNameInfo(names);
	} catch (Exception e) {
		e.printStackTrace();
		ret.clear();
		if (numRef.isSetNumCache()) {
			CTNumData data = numRef.getNumCache();
			for (int i=0; i<data.sizeOfPtArray(); i++) {
				CTNumVal pt = data.getPtArray(i);
				ret.add(Double.parseDouble(pt.getV()));
			}
		}
	}
	return ret;
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:37,代码来源:Flotr2ChartFactory.java


示例11: getCellReference

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public static CellReference getCellReference(Workbook wb, String ref) {
    Name name = wb.getName(ref);
    if(name != null)
        ref = name.getRefersToFormula();
    
    if(ref.indexOf(':') > 0) {
        AreaReference aRef = new AreaReference(ref);
        return aRef.getFirstCell();
    } else {
        return new CellReference(ref);
    }
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:13,代码来源:ExcelUtil.java


示例12: readBlock

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
/**
 * @param range either the range of the entire block to be read, or just the
 *              top row of the cells, in which case the method will stop when
 *              the first empty cell is reached in the first column
 * @param columnTypes An array of data types expected at each column.
 *                 If this array is shorter than the number of column, then the last
 *                 data type is used until the end. So if only one value is given,
 *                 then that is used for the entire block.
 */
public Object[][] readBlock(String range, Class... columnTypes) {

    if (columnTypes == null || columnTypes.length == 0) {
        throw new RuntimeException("columnTypes cannot be null / empty");
    }

    CellRangeAddress cra = CellRangeAddress.valueOf(range);
    AreaReference ar = new AreaReference(range);
    Sheet sheet = workbook.getSheet(ar.getFirstCell().getSheetName());

    int firstColumn = cra.getFirstColumn();
    int firstRow = cra.getFirstRow();
    int lastRow = cra.getLastRow();
    int height = lastRow - firstRow + 1;
    int width = cra.getLastColumn() - firstColumn + 1;

    List<Object> result;
    if (height == 1) {
        result = new LinkedList<Object>();
    } else {
        result = new ArrayList<Object>(height);
    }

    for (int rowNum = 0; moreDataToRead(sheet, firstColumn, firstRow, lastRow, rowNum); rowNum++) {
        Row row = sheet.getRow(firstRow + rowNum);
        Object[] resultRow = new Object[width];
        result.add(resultRow);
        for (int colNum = 0; colNum < width; colNum++) {

            Class colType;
            if (colNum < columnTypes.length - 1) {
                colType = columnTypes[colNum];
            } else {
                colType = columnTypes[columnTypes.length - 1];
            }

            Cell cell = row.getCell(firstColumn + colNum);
            resultRow[colNum] = readCell(cell, colType);
        }

    }

    return result.toArray(new Object[][] {});
}
 
开发者ID:Appendium,项目名称:objectlabkit,代码行数:54,代码来源:Excel.java


示例13: Area

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public Area(AreaReference areaReference) {
    topLeft = new Cell(areaReference.getFirstCell());
    bottomRight = new Cell(areaReference.getLastCell());
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:5,代码来源:Area.java


示例14: toAreaReference

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public AreaReference toAreaReference() {
    return new AreaReference(topLeft.toCellReference(), bottomRight.toCellReference());
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:4,代码来源:Area.java


示例15: initMergeRegions

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
/**
 * Method creates mapping [rangeName : List&lt;CellRangeAddress&gt;].
 * List contains all merge regions for this named range.
 * Attention: if merged regions writes wrong - look on methods isMergeRegionInsideNamedRange or isNamedRangeInsideMergeRegion
 * todo: how to recognize if merge region must be copied with named range
 *
 * @param currentSheet Sheet which contains merge regions
 */
protected void initMergeRegions(HSSFSheet currentSheet) {
    int rangeNumber = templateWorkbook.getNumberOfNames();
    for (int i = 0; i < rangeNumber; i++) {
        HSSFName aNamedRange = templateWorkbook.getNameAt(i);

        String refersToFormula = aNamedRange.getRefersToFormula();
        if (!AreaReference.isContiguous(refersToFormula)) {
            continue;
        }

        AreaReference aref = new AreaReference(refersToFormula);
        Integer rangeFirstRow = aref.getFirstCell().getRow();
        Integer rangeFirstColumn = (int) aref.getFirstCell().getCol();
        Integer rangeLastRow = aref.getLastCell().getRow();
        Integer rangeLastColumn = (int) aref.getLastCell().getCol();

        for (int j = 0; j < currentSheet.getNumMergedRegions(); j++) {
            CellRangeAddress mergedRegion = currentSheet.getMergedRegion(j);
            if (mergedRegion != null) {
                Integer regionFirstRow = mergedRegion.getFirstRow();
                Integer regionFirstColumn = mergedRegion.getFirstColumn();
                Integer regionLastRow = mergedRegion.getLastRow();
                Integer regionLastColumn = mergedRegion.getLastColumn();

                boolean mergedInsideNamed = isMergeRegionInsideNamedRange(
                        rangeFirstRow, rangeFirstColumn, rangeLastRow, rangeLastColumn,
                        regionFirstRow, regionFirstColumn, regionLastRow, regionLastColumn);

                boolean namedInsideMerged = isNamedRangeInsideMergeRegion(
                        rangeFirstRow, rangeFirstColumn, rangeLastRow, rangeLastColumn,
                        regionFirstRow, regionFirstColumn, regionLastRow, regionLastColumn);

                if (mergedInsideNamed || namedInsideMerged) {
                    String name = aNamedRange.getNameName();
                    SheetRange sheetRange = new SheetRange(mergedRegion, currentSheet.getSheetName());
                    if (mergeRegionsForRangeNames.get(name) == null) {
                        ArrayList<SheetRange> list = new ArrayList<SheetRange>();
                        list.add(sheetRange);
                        mergeRegionsForRangeNames.put(name, list);
                    } else {
                        mergeRegionsForRangeNames.get(name).add(sheetRange);
                    }
                }
            }
        }
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:56,代码来源:XLSFormatter.java


示例16: copyMergeRegions

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
/**
 * Create new merge regions in result sheet identically to range's merge regions from template.
 * Not support copy of frames and rules
 *
 * @param resultSheet            - result sheet
 * @param rangeName              - range name
 * @param firstTargetRangeRow    - first column of target range
 * @param firstTargetRangeColumn - first column of target range
 */
protected void copyMergeRegions(HSSFSheet resultSheet, String rangeName,
                                int firstTargetRangeRow, int firstTargetRangeColumn) {
    int rangeNameIdx = templateWorkbook.getNameIndex(rangeName);
    if (rangeNameIdx == -1) return;

    HSSFName aNamedRange = templateWorkbook.getNameAt(rangeNameIdx);
    AreaReference aref = new AreaReference(aNamedRange.getRefersToFormula());
    int column = aref.getFirstCell().getCol();
    int row = aref.getFirstCell().getRow();

    List<SheetRange> regionsList = mergeRegionsForRangeNames.get(rangeName);
    if (regionsList != null)
        for (SheetRange sheetRange : regionsList) {
            if (resultSheet.getSheetName().equals(sheetRange.getSheetName())) {
                CellRangeAddress cra = sheetRange.getCellRangeAddress();
                if (cra != null) {
                    int regionHeight = cra.getLastRow() - cra.getFirstRow() + 1;
                    int regionWidth = cra.getLastColumn() - cra.getFirstColumn() + 1;

                    int regionVOffset = cra.getFirstRow() - row;
                    int regionHOffset = cra.getFirstColumn() - column;

                    CellRangeAddress newRegion = cra.copy();
                    newRegion.setFirstColumn(regionHOffset + firstTargetRangeColumn);
                    newRegion.setLastColumn(regionHOffset + regionWidth - 1 + firstTargetRangeColumn);

                    newRegion.setFirstRow(regionVOffset + firstTargetRangeRow);
                    newRegion.setLastRow(regionVOffset + regionHeight - 1 + firstTargetRangeRow);

                    boolean skipRegion = false;

                    for (int mergedIndex = 0; mergedIndex < resultSheet.getNumMergedRegions(); mergedIndex++) {
                        CellRangeAddress mergedRegion = resultSheet.getMergedRegion(mergedIndex);

                        if (!intersects(newRegion, mergedRegion)) {
                            continue;
                        }

                        skipRegion = true;
                    }

                    if (!skipRegion) {
                        resultSheet.addMergedRegion(newRegion);
                    }
                }
            }
        }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:58,代码来源:XLSFormatter.java


示例17: TempName

import org.apache.poi.ss.util.AreaReference; //导入依赖的package包/类
public TempName(Name name, AreaReference area, int mrCount) {
	this.name = name;
	this.area = area;
	this.relatedMergedRegion = new BitSet(mrCount);
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:6,代码来源:ExcelUtils.java



注:本文中的org.apache.poi.ss.util.AreaReference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CoroutineLib类代码示例发布时间:2022-05-22
下一篇:
Java ThreadContext类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap