Search in sources :

Example 1 with NameCommentRecord

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

the class TestLinkTable method testNameCommentRecordBetweenNameRecords.

/**
	 *
	 */
public void testNameCommentRecordBetweenNameRecords() {
    final Record[] recs = { new NameRecord(), new NameCommentRecord("name1", "comment1"), new NameRecord(), new NameCommentRecord("name2", "comment2") };
    final List<Record> recList = Arrays.asList(recs);
    final WorkbookRecordList wrl = new WorkbookRecordList();
    final Map<String, NameCommentRecord> commentRecords = new LinkedHashMap<String, NameCommentRecord>();
    final LinkTable lt = new LinkTable(recList, 0, wrl, commentRecords);
    assertNotNull(lt);
    assertEquals(2, commentRecords.size());
    //== is intentionally not .equals()!
    assertTrue(recs[1] == commentRecords.get("name1"));
    //== is intentionally not .equals()!
    assertTrue(recs[3] == commentRecords.get("name2"));
    assertEquals(2, lt.getNumNames());
}
Also used : ExternalNameRecord(org.apache.poi.hssf.record.ExternalNameRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) Record(org.apache.poi.hssf.record.Record) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) ExternalNameRecord(org.apache.poi.hssf.record.ExternalNameRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with NameCommentRecord

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

the class InternalWorkbook method createWorkbook.

/**
     * read support  for low level
     * API.  Pass in an array of Record objects, A Workbook
     * object is constructed and passed back with all of its initialization set
     * to the passed in records and references to those records held. Unlike Sheet
     * workbook does not use an offset (its assumed to be 0) since its first in a file.
     * If you need an offset then construct a new array with a 0 offset or write your
     * own ;-p.
     *
     * @param recs an array of Record objects
     * @return Workbook object
     */
public static InternalWorkbook createWorkbook(List<Record> recs) {
    LOG.log(DEBUG, "Workbook (readfile) created with reclen=", recs.size());
    InternalWorkbook retval = new InternalWorkbook();
    List<Record> records = new ArrayList<Record>(recs.size() / 3);
    retval.records.setRecords(records);
    boolean eofPassed = false;
    for (int k = 0; k < recs.size(); k++) {
        Record rec = recs.get(k);
        String logObj;
        switch(rec.getSid()) {
            case EOFRecord.sid:
                logObj = "workbook eof";
                break;
            case BoundSheetRecord.sid:
                logObj = "boundsheet";
                retval.boundsheets.add((BoundSheetRecord) rec);
                retval.records.setBspos(k);
                break;
            case SSTRecord.sid:
                logObj = "sst";
                retval.sst = (SSTRecord) rec;
                break;
            case FontRecord.sid:
                logObj = "font";
                retval.records.setFontpos(k);
                retval.numfonts++;
                break;
            case ExtendedFormatRecord.sid:
                logObj = "XF";
                retval.records.setXfpos(k);
                retval.numxfs++;
                break;
            case TabIdRecord.sid:
                logObj = "tabid";
                retval.records.setTabpos(k);
                break;
            case ProtectRecord.sid:
                logObj = "protect";
                retval.records.setProtpos(k);
                break;
            case BackupRecord.sid:
                logObj = "backup";
                retval.records.setBackuppos(k);
                break;
            case ExternSheetRecord.sid:
                throw new RecordFormatException("Extern sheet is part of LinkTable");
            case NameRecord.sid:
            case SupBookRecord.sid:
                // LinkTable can start with either of these
                LOG.log(DEBUG, "found SupBook record at " + k);
                retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
                k += retval.linkTable.getRecordCount() - 1;
                continue;
            case FormatRecord.sid:
                logObj = "format";
                FormatRecord fr = (FormatRecord) rec;
                retval.formats.add(fr);
                retval.maxformatid = retval.maxformatid >= fr.getIndexCode() ? retval.maxformatid : fr.getIndexCode();
                break;
            case DateWindow1904Record.sid:
                logObj = "datewindow1904";
                retval.uses1904datewindowing = ((DateWindow1904Record) rec).getWindowing() == 1;
                break;
            case PaletteRecord.sid:
                logObj = "palette";
                retval.records.setPalettepos(k);
                break;
            case WindowOneRecord.sid:
                logObj = "WindowOneRecord";
                retval.windowOne = (WindowOneRecord) rec;
                break;
            case WriteAccessRecord.sid:
                logObj = "WriteAccess";
                retval.writeAccess = (WriteAccessRecord) rec;
                break;
            case WriteProtectRecord.sid:
                logObj = "WriteProtect";
                retval.writeProtect = (WriteProtectRecord) rec;
                break;
            case FileSharingRecord.sid:
                logObj = "FileSharing";
                retval.fileShare = (FileSharingRecord) rec;
                break;
            case NameCommentRecord.sid:
                logObj = "NameComment";
                final NameCommentRecord ncr = (NameCommentRecord) rec;
                retval.commentRecords.put(ncr.getNameText(), ncr);
                break;
            case HyperlinkRecord.sid:
                // Look for other interesting values that follow the EOFRecord
                logObj = "Hyperlink";
                retval.hyperlinks.add((HyperlinkRecord) rec);
                break;
            default:
                logObj = "(sid=" + rec.getSid() + ")";
                break;
        }
        if (!eofPassed) {
            records.add(rec);
        }
        LOG.log(DEBUG, "found " + logObj + " record at " + k);
        if (rec.getSid() == EOFRecord.sid) {
            eofPassed = true;
        }
    }
    if (retval.windowOne == null) {
        retval.windowOne = createWindowOne();
    }
    LOG.log(DEBUG, "exit create workbook from existing file function");
    return retval;
}
Also used : RecordFormatException(org.apache.poi.util.RecordFormatException) ArrayList(java.util.ArrayList) WindowProtectRecord(org.apache.poi.hssf.record.WindowProtectRecord) PasswordRev4Record(org.apache.poi.hssf.record.PasswordRev4Record) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) BookBoolRecord(org.apache.poi.hssf.record.BookBoolRecord) StyleRecord(org.apache.poi.hssf.record.StyleRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HideObjRecord(org.apache.poi.hssf.record.HideObjRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) ProtectionRev4Record(org.apache.poi.hssf.record.ProtectionRev4Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) MMSRecord(org.apache.poi.hssf.record.MMSRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) FnGroupCountRecord(org.apache.poi.hssf.record.FnGroupCountRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) WriteAccessRecord(org.apache.poi.hssf.record.WriteAccessRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) CodepageRecord(org.apache.poi.hssf.record.CodepageRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) UseSelFSRecord(org.apache.poi.hssf.record.UseSelFSRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) WriteProtectRecord(org.apache.poi.hssf.record.WriteProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) DSFRecord(org.apache.poi.hssf.record.DSFRecord) InterfaceEndRecord(org.apache.poi.hssf.record.InterfaceEndRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) PaletteRecord(org.apache.poi.hssf.record.PaletteRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) FileSharingRecord(org.apache.poi.hssf.record.FileSharingRecord) RefreshAllRecord(org.apache.poi.hssf.record.RefreshAllRecord) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord)

Example 3 with NameCommentRecord

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

the class TestLinkTable method testMissingExternSheetRecord_bug47001b.

/**
	 * This problem was visible in POI svn r763332
	 * when reading the workbook of attachment 23468 from bugzilla 47001
	 */
public void testMissingExternSheetRecord_bug47001b() {
    Record[] recs = { SupBookRecord.createAddInFunctions(), new SSTRecord() };
    List<Record> recList = Arrays.asList(recs);
    WorkbookRecordList wrl = new WorkbookRecordList();
    LinkTable lt;
    try {
        lt = new LinkTable(recList, 0, wrl, Collections.<String, NameCommentRecord>emptyMap());
    } catch (RuntimeException e) {
        if (e.getMessage().equals("Expected an EXTERNSHEET record but got (org.apache.poi.hssf.record.SSTRecord)")) {
            throw new AssertionFailedError("Identified bug 47001b");
        }
        throw e;
    }
    assertNotNull(lt);
}
Also used : Record(org.apache.poi.hssf.record.Record) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) ExternalNameRecord(org.apache.poi.hssf.record.ExternalNameRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) AssertionFailedError(junit.framework.AssertionFailedError) SSTRecord(org.apache.poi.hssf.record.SSTRecord)

Aggregations

BOFRecord (org.apache.poi.hssf.record.BOFRecord)3 CountryRecord (org.apache.poi.hssf.record.CountryRecord)3 EOFRecord (org.apache.poi.hssf.record.EOFRecord)3 ExternSheetRecord (org.apache.poi.hssf.record.ExternSheetRecord)3 NameCommentRecord (org.apache.poi.hssf.record.NameCommentRecord)3 NameRecord (org.apache.poi.hssf.record.NameRecord)3 Record (org.apache.poi.hssf.record.Record)3 SSTRecord (org.apache.poi.hssf.record.SSTRecord)3 SupBookRecord (org.apache.poi.hssf.record.SupBookRecord)3 ExternalNameRecord (org.apache.poi.hssf.record.ExternalNameRecord)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 AssertionFailedError (junit.framework.AssertionFailedError)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)1 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)1 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)1 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)1