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

示例1
/**
 * check if any shapes contain wrong data
 * At now(13.08.2010) check if patriarch contains 2 or more comments with same coordinates
 */
protected void preSerialize(){
    Map<Integer, NoteRecord> tailRecords = _boundAggregate.getTailRecords();
    /**
     * contains coordinates of comments we iterate over
     */
    Set<String> coordinates = new HashSet<String>(tailRecords.size());
    for(NoteRecord rec : tailRecords.values()){
        String noteRef = new CellReference(rec.getRow(),
                rec.getColumn()).formatAsString(); // A1-style notation
        if(coordinates.contains(noteRef )){
            throw new IllegalStateException("found multiple cell comments for cell " + noteRef );
        } else {
            coordinates.add(noteRef);
        }
    }
}
 
示例2
@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    NoteRecord nr = (NoteRecord)record;
    String text = xlsReadContext.xlsReadSheetHolder().getObjectCacheMap().get(nr.getShapeId());
    CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, text, nr.getRow(), nr.getColumn());
    xlsReadContext.xlsReadSheetHolder().setCellExtra(cellExtra);
    xlsReadContext.analysisEventProcessor().extra(xlsReadContext);
}
 
示例3
private HSSFComment(HSSFShape parent, HSSFAnchor anchor, NoteRecord note) {
    super(parent, anchor);
    _note = note;
    //default color for comments
    setFillColor(0x08000050);

    //by default comments are hidden
    setVisible(false);
    setAuthor("");
    CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0);
    cod.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT);
}
 
示例4
@Override
protected HSSFShape cloneShape() {
    TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
    EscherContainerRecord spContainer = new EscherContainerRecord();
    byte [] inSp = getEscherContainer().serialize();
    spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
    ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
    NoteRecord note = (NoteRecord) getNoteRecord().cloneViaReserialise();
    return new HSSFComment(spContainer, obj, txo, note);
}
 
示例5
public HSSFComment(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord, NoteRecord note) {
    super(spContainer, objRecord, textObjectRecord);
    _note = note;
}
 
示例6
protected HSSFComment(NoteRecord note, TextObjectRecord txo) {
    this(null, new HSSFClientAnchor(), note);
}
 
示例7
private static NoteRecord createNoteRecord() {
    NoteRecord note = new NoteRecord();
    note.setFlags(NoteRecord.NOTE_HIDDEN);
    note.setAuthor("");
    return note;
}
 
示例8
/**
 * Sets whether this comment is visible.
 *
 * @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
 */
@Override
public void setVisible(boolean visible) {
    _note.setFlags(visible ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
    setHidden(!visible);
}
 
示例9
/**
 * Returns the underlying Note record
 */
protected NoteRecord getNoteRecord() {
    return _note;
}
 
示例10
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);
    }
}
 
示例11
/**
 * Returns whether this comment is visible.
 *
 * @return <code>true</code> if the comment is visible, <code>false</code> otherwise
 */
@Override
public boolean isVisible() {
    return _note.getFlags() == NoteRecord.NOTE_VISIBLE;
}