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


Java CellReference類代碼示例

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


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

示例1: outputEmptyCellComment

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
/**
 * Output an empty-cell comment.
 * 
 * @throws BingSaxReadStopException
 */
private void outputEmptyCellComment(CellReference cellRef)
		throws BingSaxReadStopException {
	String cellRefString = cellRef.formatAsString();
	XSSFComment comment = commentsTable.findCellComment(cellRefString);
	output.cell(rowNum, cellRefString, null, comment);
}
 
開發者ID:bingyulei007,項目名稱:bingexcel,代碼行數:12,代碼來源:ExcelXSSFSheetXMLHandler.java

示例2: mapHeaderToCellNum

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
private int mapHeaderToCellNum(Sheet sheet, String header, boolean createHeaderIfNotExisting) {
	if(configuration.getHeaders().get()) {
		Row row = sheet.getRow(0);
		if(row!=null) {
			for(Cell cell:row) {
				String key = ExcelFunctions.getCellValueAsString(cell, workbookSet.getMainFormulaEvaluator());
				if(key!=null && key.equals(header)) {
					return cell.getColumnIndex();
				}
			}				
		} else {
			if(createHeaderIfNotExisting) {
				sheet.createRow(0);
			} else {
				throw new ValidationException("The sheet " + sheet.getSheetName() + " contains no headers");				
			}
		}
		if(createHeaderIfNotExisting) {
			return addHeader(sheet, header);
		} else {
			throw new ValidationException("The column " + header + " doesn't exist in sheet " + sheet.getSheetName());				
		}
	} else {
		return CellReference.convertColStringToIndex(header);
	}
}
 
開發者ID:denkbar,項目名稱:step,代碼行數:27,代碼來源:ExcelDataPoolImpl.java

示例3: getLocation

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
@Override
public TableImportLocation getLocation(Sheet sheet, Row row, CellReference cellReference) {
	String sheetName = null;
	Integer rowIndex = null;
	String cellAddress = null;
	if (sheet != null) {
		sheetName = sheet.getSheetName();
	}
	if (row != null) {
		rowIndex = row.getRowNum();
	}
	if (cellReference != null) {
		cellAddress = cellReference.formatAsString();
	}
	return new TableImportLocation(fileName, sheetName, rowIndex, cellAddress);
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:17,代碼來源:ApachePoiImportNavigator.java

示例4: getReferenceList

import org.apache.poi.ss.util.CellReference; //導入依賴的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

示例5: convertColumnIndex

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
protected int convertColumnIndex(Column column, String columnNumber) {
	int index;
	try {
		char c = columnNumber.charAt(0);
		if ('0' <= c && c <= '9') {
			index = Integer.parseInt(columnNumber) - 1;
		} else {
			index = CellReference.convertColStringToIndex(columnNumber);
		}
	} catch (Exception e) {
		throw new RuntimeException(MessageFormat.format("illegal column_number=\"{0}\" at {1}", columnNumber,
				column), e);
	}
	if (index < 0) {
		throw new RuntimeException(MessageFormat.format("illegal column_number=\"{0}\" at {1}", columnNumber,
				column));
	}
	return index;
}
 
開發者ID:hishidama,項目名稱:embulk-parser-poi_excel,代碼行數:20,代碼來源:PoiExcelColumnIndex.java

示例6: createName

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
protected void createName(HandlerState state, String bookmark, int row1, int col1, int row2, int col2 ) {
	CellReference crFirst = new CellReference( state.currentSheet.getSheetName(), row1, col1, true, true );
	CellReference crLast = new CellReference( row2, col2, true, true );
	String formula = crFirst.formatAsString() + ":" + crLast.formatAsString();

	Name name = state.currentSheet.getWorkbook().getName(bookmark);
	if( name == null ) {
		name = state.currentSheet.getWorkbook().createName();
		name.setNameName( bookmark ); 
		name.setRefersToFormula( formula );
	} else {
		String existingFormula = name.getRefersToFormula();
		try {
			name.setRefersToFormula(existingFormula + "," + formula);
		} catch( FormulaParseException ex ) {
			log.warn( 0, "Unable to add \"" + formula + "\" to name (\"" + bookmark + "\") with existing formula: " + existingFormula, ex );
		}
	}
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:20,代碼來源:AbstractHandler.java

示例7: createCellBlank

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
protected Cell createCellBlank(String cellName)
{
	System.out.println("se crea la celda : " + cellName);

	CellData cellData = getCellDataByCellName(cellName);
	CellReference cellReference = new CellReference(cellData.cellRef);
	Row row = cellData.sheet.getRow(cellReference.getRow());

	//la fila puede no existir
	if(row == null)
	{
		row = cellData.sheet.createRow(cellReference.getRow());	
	}
	
	Cell cell = row.createCell(cellReference.getCol());
	
	return cell;
	
}
 
開發者ID:rodrigoEclipsa,項目名稱:excelToApp,代碼行數:20,代碼來源:ExcelBase.java

示例8: getEmptyRow

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
public static int getEmptyRow(Workbook wb, int sheetIndex, String cellRef) {
	final Sheet sheet = wb.getSheetAt(sheetIndex);
	final CellReference cellReference = new CellReference(cellRef); // һ����A1
	boolean flag = false;
	for (int i = cellReference.getRow(); i <= sheet.getLastRowNum();) {
		final Row r = sheet.getRow(i);
		if (r == null) {
			// ����ǿ��У���û���κ����ݡ���ʽ����ֱ�Ӱ������µ����������ƶ�
			sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
			continue;
		}
		flag = false;
		for (final Cell c : r) {
			if (c.getCellType() != Cell.CELL_TYPE_BLANK) {
				flag = true;
				break;
			}
		}
		if (flag) {
			i++;
			continue;
		} else {// ����ǿհ��У�������û�����ݣ�������һ����ʽ��
			if (i == sheet.getLastRowNum())// ����������һ�У�ֱ�ӽ���һ��remove��
				sheet.removeRow(r);
			else// �����û�����һ�У�������������һ��
				sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
		}
	}
	return sheet.getLastRowNum() + 1;
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:31,代碼來源:ExcelOperation.java

示例9: formatCellStatus

import org.apache.poi.ss.util.CellReference; //導入依賴的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: main

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
public static void main(String[] args) throws Throwable {
        SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
        Sheet sh = wb.createSheet();
        for (int rownum = 0; rownum < 1000; rownum++) {
            Row row = sh.createRow(rownum);
            Row row1 = sh.createRow(rownum);
            for (int cellnum = 0; cellnum < 10; cellnum++) {
                Cell cell = row.createCell(cellnum);
                String address = new CellReference(cell).formatAsString();
                cell.setCellValue(address);
            }

        }

        // Rows with rownum < 900 are flushed and not accessible
//        for (int rownum = 0; rownum < 103857; rownum++) {
//            Assert.assertNull(sh.getRow(rownum));
//        }
//
//        // ther last 100 rows are still in memory
//        for (int rownum = 103857; rownum < 104857; rownum++) {
//            Assert.assertNotNull(sh.getRow(rownum));
//        }

        File file = new File("C:\\Users\\FlyingHe\\Desktop", "datas.xlsx");
        FileOutputStream out = new FileOutputStream(file);
        wb.write(out);
        out.close();

        // dispose of temporary files backing this workbook on disk
        wb.dispose();
    }
 
開發者ID:FlyingHe,項目名稱:UtilsMaven,代碼行數:33,代碼來源:Example.java

示例11: process

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
public void process(Record r) {
  switch (r.getSid()) {
    case MergeCellsRecord.sid:
      mergeCellRecords.add((MergeCellsRecord) r);
      break;
    case SharedFormulaRecord.sid:
      shFrmRecords.add((SharedFormulaRecord) r);
      if (!(prevRec instanceof FormulaRecord)) {
        throw new RuntimeException("Shared formula record should follow a FormulaRecord");
      }
      FormulaRecord fr = (FormulaRecord) prevRec;
      firstCellRefs.add(new CellReference(fr.getRow(), fr.getColumn()));
      break;
    case ArrayRecord.sid:
      arrayRecords.add((ArrayRecord) r);
      break;
    case TableRecord.sid:
      tableRecords.add((TableRecord) r);
      break;
    default:
      plainRecords.add(r);
      break;
  }
  prevRec = r;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:26,代碼來源:RowBlock.java

示例12: updateCellValue

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
public void updateCellValue(String cellPosition, String value) throws Exception {
    
    String sheetNumTxt = cellPosition.indexOf("[")>-1 ? cellPosition.substring(cellPosition.indexOf("[")) : null;
        if(sheetNumTxt != null) {
            this.sheetNum = new Integer(sheetNumTxt.substring(0,sheetNumTxt.length()-1));
            cellPosition = cellPosition.substring(cellPosition.indexOf("["));
        } else {
            this.sheetNum = 0;
        }
        worksheet = workbook.getSheetAt(this.sheetNum);
    
    CellReference c = new CellReference(cellPosition);
    XSSFCell cell = worksheet.getRow(c.getRow()).getCell(c.getCol());
    if(cell == null) throw new Exception("Invalid cell reference:" + cellPosition);
    if(value == null) {
       cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
    } else if(cell.getCellType()==XSSFCell.CELL_TYPE_FORMULA) {
        this.setCellFormula(cell, value);
    } else {
        cell.setCellValue(value);
    }
}
 
開發者ID:linearblue,項目名稱:ExcelInjector,代碼行數:23,代碼來源:ExcelTableInjector.java

示例13: asDouble

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
@Override
public DoubleState<Sheet, Row, Cell, CellReference> asDouble() {
	return new TypeStateSwitcher<Cell>(Functions.<Cell>identity()).toDouble(new Function<Cell, Double>() {
		@Override
		public Double apply(Cell cell) {
			if (cell == null) {
				return null;
			}
			
			switch(ApachePoiImportUtils.getCellActualValueType(cell)) {
				case Cell.CELL_TYPE_NUMERIC:
					return cell.getNumericCellValue();
				default:
					return null;
			}
		}
	});
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:19,代碼來源:ApachePoiImportColumnBuilder.java

示例14: asString

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
@Override
public StringState<Sheet, Row, Cell, CellReference> asString(final Supplier<? extends NumberFormat> formatIfNumeric) {
	return new TypeStateSwitcher<Cell>(Functions.<Cell>identity()).toString(new Function<Cell, String>() {
		@Override
		public String apply(Cell cell) {
			if (cell == null) {
				return null;
			}
			
			switch(ApachePoiImportUtils.getCellActualValueType(cell)) {
				case Cell.CELL_TYPE_NUMERIC:
					return formatIfNumeric.get().format(cell.getNumericCellValue());
				case Cell.CELL_TYPE_STRING:
					return StringUtils.trimToNull(cell.getStringCellValue());
				default:
					return null;
			}
		}
	});
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:21,代碼來源:ApachePoiImportColumnBuilder.java

示例15: asDate

import org.apache.poi.ss.util.CellReference; //導入依賴的package包/類
@Override
public DateState<Sheet, Row, Cell, CellReference> asDate() {
	return new TypeStateSwitcher<Cell>(Functions.<Cell>identity()).toDate(new Function<Cell, Date>() {
		@Override
		public Date apply(Cell cell) {
			if (cell == null) {
				return null;
			}
			
			switch(ApachePoiImportUtils.getCellActualValueType(cell)) {
				case Cell.CELL_TYPE_STRING:
					return null;
				default:
					return cell.getDateCellValue();
			}
		}
	});
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:19,代碼來源:ApachePoiImportColumnBuilder.java


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