Java源码示例:org.apache.poi.hssf.record.StringRecord

示例1
@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    // String for formula
    StringRecord srec = (StringRecord)record;
    XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
    CellData tempCellData = xlsReadSheetHolder.getTempCellData();
    if (tempCellData == null) {
        LOGGER.warn("String type formula but no value found.");
        return;
    }
    tempCellData.setStringValue(srec.getString());
    xlsReadSheetHolder.getCellMap().put(tempCellData.getColumnIndex(), tempCellData);
    xlsReadSheetHolder.setTempCellData(null);
}
 
示例2
/**
 * @param stringRec may be <code>null</code> if this formula does not have a cached text
 * value.
 * @param svm the {@link SharedValueManager} for the current sheet
 */
public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm) {
	if (svm == null) {
		throw new IllegalArgumentException("sfm must not be null");
	}
	if (formulaRec.hasCachedResultString()) {
		if (stringRec == null) {
			throw new RecordFormatException("Formula record flag is set but String record was not found");
		}
		_stringRecord = stringRec;
	} else {
		// Usually stringRec is null here (in agreement with what the formula rec says).
		// In the case where an extra StringRecord is erroneously present, Excel (2007)
		// ignores it (see bug 46213).
		_stringRecord = null;
	}

	_formulaRecord = formulaRec;
	_sharedValueManager = svm;
	if (formulaRec.isSharedFormula()) {
		CellReference firstCell = formulaRec.getFormula().getExpReference();
		if (firstCell == null) {
			handleMissingSharedFormulaRecord(formulaRec);
		} else {
			_sharedFormulaRecord = svm.linkSharedFormulaRecord(firstCell, this);
		}
	}
}
 
示例3
public void processRecord(Record record) {
    String thisText = null;
    int thisRow = -1;

    switch(record.getSid()) {
    case BoundSheetRecord.sid:
        BoundSheetRecord sr = (BoundSheetRecord)record;
        sheetNames.add(sr.getSheetname());
        break;
    case BOFRecord.sid:
        BOFRecord bof = (BOFRecord)record;
        if(bof.getType() == BOFRecord.TYPE_WORKSHEET) {
            sheetNum++;
            rowNum = -1;

            if(_includeSheetNames) {
                if(_text.length() > 0) _text.append("\n");
                _text.append(sheetNames.get(sheetNum));
            }
        }
        break;
    case SSTRecord.sid:
        sstRecord = (SSTRecord)record;
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;
        thisRow = frec.getRow();

        if(_formulasNotResults) {
            thisText = HSSFFormulaParser.toFormulaString((HSSFWorkbook)null, frec.getParsedExpression());
        } else {
            if(frec.hasCachedResultString()) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringValue = true;
                nextRow = frec.getRow();
            } else {
                thisText = _ft.formatNumberDateCell(frec);
            }
        }
        break;
    case StringRecord.sid:
        if(outputNextStringValue) {
            // String for formula
            StringRecord srec = (StringRecord)record;
            thisText = srec.getString();
            thisRow = nextRow;
            outputNextStringValue = false;
        }
        break;
    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;
        thisRow = lrec.getRow();
        thisText = lrec.getValue();
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;
        thisRow = lsrec.getRow();
        if(sstRecord == null) {
            throw new IllegalStateException("No SST record found");
        }
        thisText = sstRecord.getString(lsrec.getSSTIndex()).toString();
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;
        thisRow = nrec.getRow();
        // TODO: Find object to match nrec.getShapeId()
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;
        thisRow = numrec.getRow();
        thisText = _ft.formatNumberDateCell(numrec);
        break;
    default:
        break;
    }

    if(thisText != null) {
        if(thisRow != rowNum) {
            rowNum = thisRow;
            if(_text.length() > 0)
                _text.append("\n");
        } else {
            _text.append("\t");
        }
        _text.append(thisText);
    }
}
 
示例4
/**
 * debug only
 * TODO - encapsulate
 */
public StringRecord getStringRecord() {
	return _stringRecord;
}