Search in sources :

Example 1 with NoteRecord

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

the class TestSheet method testCreateAggregate.

@Test
public void testCreateAggregate() {
    String msoDrawingRecord1 = "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" + "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" + "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" + "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" + "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" + "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" + "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" + "05 00 94 00 00 00 11 F0 00 00 00 00";
    String msoDrawingRecord2 = "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " + "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " + "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " + "0B 00 0C 00 00 00 11 F0 00 00 00 00";
    DrawingRecord d1 = new DrawingRecord();
    d1.setData(HexRead.readFromString(msoDrawingRecord1));
    ObjRecord r1 = new ObjRecord();
    DrawingRecord d2 = new DrawingRecord();
    d2.setData(HexRead.readFromString(msoDrawingRecord2));
    TextObjectRecord r2 = new TextObjectRecord();
    r2.setStr(new HSSFRichTextString("Aggregated"));
    NoteRecord n2 = new NoteRecord();
    List<Record> recordStream = new ArrayList<Record>();
    recordStream.add(InternalSheet.createBOF());
    recordStream.add(d1);
    recordStream.add(r1);
    recordStream.add(createWindow2Record());
    recordStream.add(EOFRecord.instance);
    confirmAggregatedRecords(recordStream);
    recordStream = new ArrayList<Record>();
    recordStream.add(InternalSheet.createBOF());
    recordStream.add(d1);
    recordStream.add(r1);
    recordStream.add(d2);
    recordStream.add(r2);
    recordStream.add(createWindow2Record());
    recordStream.add(EOFRecord.instance);
    confirmAggregatedRecords(recordStream);
    recordStream = new ArrayList<Record>();
    recordStream.add(InternalSheet.createBOF());
    recordStream.add(d1);
    recordStream.add(r1);
    recordStream.add(d2);
    recordStream.add(r2);
    recordStream.add(n2);
    recordStream.add(createWindow2Record());
    recordStream.add(EOFRecord.instance);
    confirmAggregatedRecords(recordStream);
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) NoteRecord(org.apache.poi.hssf.record.NoteRecord) ArrayList(java.util.ArrayList) ObjRecord(org.apache.poi.hssf.record.ObjRecord) StringRecord(org.apache.poi.hssf.record.StringRecord) GutsRecord(org.apache.poi.hssf.record.GutsRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) Test(org.junit.Test)

Example 2 with NoteRecord

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

the class HSSFComment method cloneShape.

@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);
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 3 with NoteRecord

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

the class HSSFComment method createNoteRecord.

private static NoteRecord createNoteRecord() {
    NoteRecord note = new NoteRecord();
    note.setFlags(NoteRecord.NOTE_HIDDEN);
    note.setAuthor("");
    return note;
}
Also used : NoteRecord(org.apache.poi.hssf.record.NoteRecord)

Example 4 with NoteRecord

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

the class TestHSSFComment method resultEqualsToNonExistingAbstractShape.

@Test
public void resultEqualsToNonExistingAbstractShape() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sh = wb.createSheet();
    HSSFPatriarch patriarch = sh.createDrawingPatriarch();
    HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
    HSSFRow row = sh.createRow(0);
    HSSFCell cell = row.createCell(0);
    cell.setCellComment(comment);
    assertEquals(comment.getEscherContainer().getChildRecords().size(), 5);
    //sp record
    byte[] expected = decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA=");
    byte[] actual = comment.getEscherContainer().getChild(0).serialize();
    assertEquals(expected.length, actual.length);
    assertArrayEquals(expected, actual);
    expected = decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA==");
    actual = comment.getEscherContainer().getChild(2).serialize();
    assertEquals(expected.length, actual.length);
    assertArrayEquals(expected, actual);
    expected = decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA=");
    actual = comment.getEscherContainer().getChild(3).serialize();
    assertEquals(expected.length, actual.length);
    assertArrayEquals(expected, actual);
    expected = decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA=");
    actual = comment.getEscherContainer().getChild(4).serialize();
    assertEquals(expected.length, actual.length);
    assertArrayEquals(expected, actual);
    ObjRecord obj = comment.getObjRecord();
    expected = decompress("H4sIAAAAAAAAAItlMGEQZRBikGRgZBF0YEACvAxiDLgBAJZsuoU4AAAA");
    actual = obj.serialize();
    assertEquals(expected.length, actual.length);
    //assertArrayEquals(expected, actual);
    TextObjectRecord tor = comment.getTextObjectRecord();
    expected = decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA==");
    actual = tor.serialize();
    assertEquals(expected.length, actual.length);
    assertArrayEquals(expected, actual);
    NoteRecord note = comment.getNoteRecord();
    expected = decompress("H4sIAAAAAAAAAJNh4GGAAEYWEAkAS0KXuRAAAAA=");
    actual = note.serialize();
    assertEquals(expected.length, actual.length);
    assertArrayEquals(expected, actual);
    wb.close();
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) Test(org.junit.Test)

Example 5 with NoteRecord

use of org.apache.poi.hssf.record.NoteRecord in project jeesuite-libs by vakinge.

the class XLS2CSV method processRecord.

/**
 * Main HSSFListener method, processes events, and outputs the
 *  CSV as the file is processed.
 */
public void processRecord(Record record) {
    // 超过10行空白就不处理了
    if (blankRowNum == 10)
        return;
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;
    switch(record.getSid()) {
        case BoundSheetRecord.sid:
            boundSheetRecords.add((BoundSheetRecord) record);
            break;
        case BOFRecord.sid:
            BOFRecord br = (BOFRecord) record;
            if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
                // Create sub workbook if required
                if (workbookBuildingListener != null && stubWorkbook == null) {
                    stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
                }
                // Output the worksheet name
                // Works by ordering the BSRs by the location of
                // their BOFRecords, and then knowing that we
                // process BOFRecords in byte offset order
                sheetIndex++;
                if (orderedBSRs == null) {
                    orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
                }
                // sheetName
                // System.out.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex+1) + "]:" );
                String sheetname = orderedBSRs[sheetIndex].getSheetname();
                results.add(ExcelValidator.SHEET_NAME_PREFIX + sheetname);
            }
            break;
        case SSTRecord.sid:
            sstRecord = (SSTRecord) record;
            break;
        case BlankRecord.sid:
            BlankRecord brec = (BlankRecord) record;
            thisRow = brec.getRow();
            thisColumn = brec.getColumn();
            thisStr = "";
            break;
        case BoolErrRecord.sid:
            BoolErrRecord berec = (BoolErrRecord) record;
            thisRow = berec.getRow();
            thisColumn = berec.getColumn();
            thisStr = "";
            break;
        case FormulaRecord.sid:
            FormulaRecord frec = (FormulaRecord) record;
            thisRow = frec.getRow();
            thisColumn = frec.getColumn();
            if (outputFormulaValues) {
                if (Double.isNaN(frec.getValue())) {
                    // Formula result is a string
                    // This is stored in the next record
                    outputNextStringRecord = true;
                    nextRow = frec.getRow();
                    nextColumn = frec.getColumn();
                } else {
                    thisStr = formatListener.formatNumberDateCell(frec);
                }
            } else {
                thisStr = HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression());
            }
            break;
        case StringRecord.sid:
            if (outputNextStringRecord) {
                // String for formula
                StringRecord srec = (StringRecord) record;
                thisStr = srec.getString();
                thisRow = nextRow;
                thisColumn = nextColumn;
                outputNextStringRecord = false;
            }
            break;
        case LabelRecord.sid:
            LabelRecord lrec = (LabelRecord) record;
            thisRow = lrec.getRow();
            thisColumn = lrec.getColumn();
            thisStr = lrec.getValue();
            break;
        case LabelSSTRecord.sid:
            LabelSSTRecord lsrec = (LabelSSTRecord) record;
            thisRow = lsrec.getRow();
            thisColumn = lsrec.getColumn();
            if (sstRecord == null) {
                thisStr = "(No SST Record, can't identify string)";
            } else {
                thisStr = sstRecord.getString(lsrec.getSSTIndex()).toString();
            }
            break;
        case NoteRecord.sid:
            NoteRecord nrec = (NoteRecord) record;
            thisRow = nrec.getRow();
            thisColumn = nrec.getColumn();
            // TODO: Find object to match nrec.getShapeId()
            thisStr = "(TODO)";
            break;
        case NumberRecord.sid:
            NumberRecord numrec = (NumberRecord) record;
            thisRow = numrec.getRow();
            thisColumn = numrec.getColumn();
            // Format
            thisStr = formatListener.formatNumberDateCell(numrec);
            break;
        case RKRecord.sid:
            RKRecord rkrec = (RKRecord) record;
            thisRow = rkrec.getRow();
            thisColumn = rkrec.getColumn();
            thisStr = "(TODO)";
            break;
        default:
            break;
    }
    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }
    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }
    if (thisStr != null) {
        if (thisColumn > 0) {
            _resultRowTmp.append(ExcelValidator.FIELD_SPLIT);
        }
        _resultRowTmp.append(thisStr);
    }
    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;
    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // Print out any missing commas if needed
        if (minColumns > 0) {
            // Columns are 0 based
            if (lastColumnNumber == -1) {
                lastColumnNumber = 0;
            }
            for (int i = lastColumnNumber; i < (minColumns); i++) {
                _resultRowTmp.append(',');
            }
        }
        // We're onto a new row
        lastColumnNumber = -1;
        // End the row
        if (!ExcelValidator.isBlankCSVRow(_resultRowTmp.toString())) {
            results.add(_resultRowTmp.toString());
        } else {
            blankRowNum = blankRowNum + 1;
        }
        _resultRowTmp.setLength(0);
    }
}
Also used : BlankRecord(org.apache.poi.hssf.record.BlankRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) LabelRecord(org.apache.poi.hssf.record.LabelRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) StringRecord(org.apache.poi.hssf.record.StringRecord) BoolErrRecord(org.apache.poi.hssf.record.BoolErrRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) RKRecord(org.apache.poi.hssf.record.RKRecord) LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) MissingCellDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)

Aggregations

NoteRecord (org.apache.poi.hssf.record.NoteRecord)9 BOFRecord (org.apache.poi.hssf.record.BOFRecord)4 StringRecord (org.apache.poi.hssf.record.StringRecord)4 LastCellOfRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord)3 MissingCellDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)3 BlankRecord (org.apache.poi.hssf.record.BlankRecord)3 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)3 NumberRecord (org.apache.poi.hssf.record.NumberRecord)3 ObjRecord (org.apache.poi.hssf.record.ObjRecord)3 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)3 ArrayList (java.util.ArrayList)2 BoolErrRecord (org.apache.poi.hssf.record.BoolErrRecord)2 LabelRecord (org.apache.poi.hssf.record.LabelRecord)2 LabelSSTRecord (org.apache.poi.hssf.record.LabelSSTRecord)2 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)2 RKRecord (org.apache.poi.hssf.record.RKRecord)2 RowRecord (org.apache.poi.hssf.record.RowRecord)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)1