org.apache.poi.hssf.record.LabelRecord Java Examples

The following examples show how to use org.apache.poi.hssf.record.LabelRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecordOrderer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return <code>true</code> if the specified record id normally appears in the row blocks section
 * of the sheet records
 */
public static boolean isRowBlockRecord(int sid) {
	switch (sid) {
		case RowRecord.sid:

		case BlankRecord.sid:
		case BoolErrRecord.sid:
		case FormulaRecord.sid:
		case LabelRecord.sid:
		case LabelSSTRecord.sid:
		case NumberRecord.sid:
		case RKRecord.sid:

		case ArrayRecord.sid:
		case SharedFormulaRecord.sid:
		case TableRecord.sid:
			return true;
	}
	return false;
}
 
Example #2
Source File: RowBlock.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
static boolean isRowBlockRecord(int sid) {
  switch (sid) {
    case RowRecord.sid:

    case BlankRecord.sid:
    case BoolErrRecord.sid:
    case FormulaRecord.sid:
    case LabelRecord.sid:
    case LabelSSTRecord.sid:
    case NumberRecord.sid:
    case RKRecord.sid:

    case ArrayRecord.sid:
    case SharedFormulaRecord.sid:
    case TableRecord.sid:
      return true;
  }
  return false;
}
 
Example #3
Source File: LabelRecordHandler.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    LabelRecord lrec = (LabelRecord)record;
    String data = lrec.getValue();
    if (data != null && xlsReadContext.currentReadHolder().globalConfiguration().getAutoTrim()) {
        data = data.trim();
    }
    xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)lrec.getColumn(),
        CellData.newInstance(data, lrec.getRow(), (int)lrec.getColumn()));
    xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA);
}
 
Example #4
Source File: HSSFWorkbook.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is basically a kludge to deal with the now obsolete Label records.  If
 * you have to read in a sheet that contains Label records, be aware that the rest
 * of the API doesn't deal with them, the low level structure only provides read-only
 * semi-immutable structures (the sets are there for interface conformance with NO
 * Implementation).  In short, you need to call this function passing it a reference
 * to the Workbook object.  All labels will be converted to LabelSST records and their
 * contained strings will be written to the Shared String table (SSTRecord) within
 * the Workbook.
 *
 * @param records a collection of sheet's records.
 * @param offset the offset to search at
 * @see org.apache.poi.hssf.record.LabelRecord
 * @see org.apache.poi.hssf.record.LabelSSTRecord
 * @see org.apache.poi.hssf.record.SSTRecord
 */

private void convertLabelRecords(List<Record> records, int offset)
{
    if (log.check( POILogger.DEBUG )) {
       log.log(POILogger.DEBUG, "convertLabelRecords called");
   }
    for (int k = offset; k < records.size(); k++)
    {
        Record rec = records.get(k);

        if (rec.getSid() == LabelRecord.sid)
        {
            LabelRecord oldrec = ( LabelRecord ) rec;

            records.remove(k);
            LabelSSTRecord newrec   = new LabelSSTRecord();
            int            stringid =
                workbook.addSSTString(new UnicodeString(oldrec.getValue()));

            newrec.setRow(oldrec.getRow());
            newrec.setColumn(oldrec.getColumn());
            newrec.setXFIndex(oldrec.getXFIndex());
            newrec.setSSTIndex(stringid);
                  records.add(k, newrec);
        }
    }
    if (log.check( POILogger.DEBUG )) {
       log.log(POILogger.DEBUG, "convertLabelRecords exit");
   }
}
 
Example #5
Source File: EventBasedExcelExtractor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}