Search in sources :

Example 6 with LabelSSTRecord

use of org.apache.poi.hssf.record.LabelSSTRecord in project poi by apache.

the class TestMissingRecordAwareHSSFListener method testEndOfRowRecords.

public void testEndOfRowRecords() {
    openNormal();
    // Find the cell at 0,0
    int cell00 = -1;
    for (int i = 0; i < r.length; i++) {
        if (r[i] instanceof LabelSSTRecord) {
            LabelSSTRecord lr = (LabelSSTRecord) r[i];
            if (lr.getRow() == 0 && lr.getColumn() == 0) {
                cell00 = i;
            }
        }
    }
    assertTrue(cell00 > -1);
    // We have rows 0, 1, 2, 20 and 21
    // Row 0 has 1 entry
    // Row 1 has 4 entries
    // Row 2 has 6 entries
    // Row 20 has 5 entries
    // Row 21 has 7 entries
    // Row 22 has 12 entries
    // Row 0
    assertFalse(r[cell00 + 0] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 1] instanceof LastCellOfRowDummyRecord);
    // Row 1
    assertFalse(r[cell00 + 2] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 3] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 4] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 5] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 6] instanceof LastCellOfRowDummyRecord);
    // Row 2
    assertFalse(r[cell00 + 7] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 8] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 9] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 10] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 11] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 12] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 13] instanceof LastCellOfRowDummyRecord);
    // Row 3 -> 19
    assertTrue(r[cell00 + 14] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 15] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 16] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 17] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 18] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 19] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 20] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 21] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 22] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 23] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 24] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 25] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 26] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 27] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 28] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 29] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 30] instanceof LastCellOfRowDummyRecord);
    // Row 20
    assertFalse(r[cell00 + 31] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 32] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 33] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 34] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 35] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 36] instanceof LastCellOfRowDummyRecord);
    // Row 21
    assertFalse(r[cell00 + 37] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 38] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 39] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 40] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 41] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 42] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 43] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 44] instanceof LastCellOfRowDummyRecord);
    // Row 22
    assertFalse(r[cell00 + 45] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 46] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 47] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 48] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 49] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 50] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 51] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 52] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 53] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 54] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 55] instanceof LastCellOfRowDummyRecord);
    assertFalse(r[cell00 + 56] instanceof LastCellOfRowDummyRecord);
    assertTrue(r[cell00 + 57] instanceof LastCellOfRowDummyRecord);
    // Check the numbers of the last seen columns
    LastCellOfRowDummyRecord[] lrs = new LastCellOfRowDummyRecord[24];
    int lrscount = 0;
    for (final Record rec : r) {
        if (rec instanceof LastCellOfRowDummyRecord) {
            lrs[lrscount] = (LastCellOfRowDummyRecord) rec;
            lrscount++;
        }
    }
    assertEquals(0, lrs[0].getLastColumnNumber());
    assertEquals(0, lrs[0].getRow());
    assertEquals(3, lrs[1].getLastColumnNumber());
    assertEquals(1, lrs[1].getRow());
    assertEquals(5, lrs[2].getLastColumnNumber());
    assertEquals(2, lrs[2].getRow());
    for (int i = 3; i <= 19; i++) {
        assertEquals(-1, lrs[i].getLastColumnNumber());
        assertEquals(i, lrs[i].getRow());
    }
    assertEquals(4, lrs[20].getLastColumnNumber());
    assertEquals(20, lrs[20].getRow());
    assertEquals(6, lrs[21].getLastColumnNumber());
    assertEquals(21, lrs[21].getRow());
    assertEquals(11, lrs[22].getLastColumnNumber());
    assertEquals(22, lrs[22].getRow());
}
Also used : LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) StringRecord(org.apache.poi.hssf.record.StringRecord) MissingRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord) MissingCellDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord) LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord)

Example 7 with LabelSSTRecord

use of org.apache.poi.hssf.record.LabelSSTRecord in project poi by apache.

the class HSSFWorkbook method convertLabelRecords.

/**
      * 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");
    }
}
Also used : UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) Record(org.apache.poi.hssf.record.Record) AbstractEscherHolderRecord(org.apache.poi.hssf.record.AbstractEscherHolderRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) EscherBlipRecord(org.apache.poi.ddf.EscherBlipRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) LabelRecord(org.apache.poi.hssf.record.LabelRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) LabelRecord(org.apache.poi.hssf.record.LabelRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord)

Example 8 with LabelSSTRecord

use of org.apache.poi.hssf.record.LabelSSTRecord in project poi by apache.

the class HSSFCell method convertCellValueToBoolean.

/**
     * Chooses a new boolean value for the cell when its type is changing.<p/>
     *
     * Usually the caller is calling setCellType() with the intention of calling
     * setCellValue(boolean) straight afterwards.  This method only exists to give
     * the cell a somewhat reasonable value until the setCellValue() call (if at all).
     * TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this
     */
private boolean convertCellValueToBoolean() {
    switch(_cellType) {
        case BOOLEAN:
            return ((BoolErrRecord) _record).getBooleanValue();
        case STRING:
            int sstIndex = ((LabelSSTRecord) _record).getSSTIndex();
            String text = _book.getWorkbook().getSSTString(sstIndex).getString();
            return Boolean.valueOf(text).booleanValue();
        case NUMERIC:
            return ((NumberRecord) _record).getValue() != 0;
        case FORMULA:
            // use cached formula result if it's the right type:
            FormulaRecord fr = ((FormulaRecordAggregate) _record).getFormulaRecord();
            checkFormulaCachedValueType(CellType.BOOLEAN, fr);
            return fr.getCachedBooleanValue();
        // These choices are not well justified.
        case ERROR:
        case BLANK:
            return false;
    }
    throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
}
Also used : BoolErrRecord(org.apache.poi.hssf.record.BoolErrRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) FormulaRecordAggregate(org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate) RichTextString(org.apache.poi.ss.usermodel.RichTextString) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord)

Aggregations

LabelSSTRecord (org.apache.poi.hssf.record.LabelSSTRecord)8 BoolErrRecord (org.apache.poi.hssf.record.BoolErrRecord)4 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)4 FormulaRecordAggregate (org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate)4 UnicodeString (org.apache.poi.hssf.record.common.UnicodeString)4 MissingCellDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)3 BlankRecord (org.apache.poi.hssf.record.BlankRecord)3 NumberRecord (org.apache.poi.hssf.record.NumberRecord)3 LastCellOfRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord)2 BOFRecord (org.apache.poi.hssf.record.BOFRecord)2 LabelRecord (org.apache.poi.hssf.record.LabelRecord)2 Record (org.apache.poi.hssf.record.Record)2 StringRecord (org.apache.poi.hssf.record.StringRecord)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 MissingRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord)1 AbstractEscherHolderRecord (org.apache.poi.hssf.record.AbstractEscherHolderRecord)1 BackupRecord (org.apache.poi.hssf.record.BackupRecord)1