Exemplo n.º 1
0
        private WorkbookRecordList _workbookRecordList; // TODO - would be nice to Remove this

        public LinkTable(List <Record> inputList, int startIndex, WorkbookRecordList workbookRecordList)
        {
            _workbookRecordList = workbookRecordList;
            RecordStream rs = new RecordStream(inputList, startIndex);

            ArrayList temp = new ArrayList();

            while (rs.PeekNextClass() == typeof(SupBookRecord))
            {
                temp.Add(new ExternalBookBlock(rs));
            }

            //_externalBookBlocks = new ExternalBookBlock[temp.Count];
            _externalBookBlocks = (ExternalBookBlock[])temp.ToArray(typeof(ExternalBookBlock));
            temp.Clear();

            if (_externalBookBlocks.Length > 0)
            {
                // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
                if (rs.PeekNextClass() != typeof(ExternSheetRecord))
                {
                    // not quite - if written by google docs
                    _externSheetRecord = null;
                }
                else
                {
                    _externSheetRecord = ReadExtSheetRecord(rs);
                }
            }
            else
            {
                _externSheetRecord = null;
            }

            _definedNames = new List <NameRecord>();
            // collect zero or more DEFINEDNAMEs id=0x18
            while (rs.PeekNextClass() == typeof(NameRecord))
            {
                NameRecord nr = (NameRecord)rs.GetNext();
                _definedNames.Add(nr);
            }

            _recordCount = rs.GetCountRead();
            for (int i = startIndex; i < startIndex + _recordCount; i++)
            {
                _workbookRecordList.Records.Add(inputList[i]);
            }
        }
Exemplo n.º 2
0
        public LinkTable(int numberOfSheets, WorkbookRecordList workbookRecordList)
        {
            _workbookRecordList = workbookRecordList;
            _definedNames       = new List <NameRecord>();
            _externalBookBlocks = new ExternalBookBlock[] {
                new ExternalBookBlock(numberOfSheets),
            };
            _externSheetRecord = new ExternSheetRecord();
            _recordCount       = 2;

            // tell _workbookRecordList about the 2 new records

            SupBookRecord supbook = _externalBookBlocks[0].GetExternalBookRecord();

            int idx = FindFirstRecordLocBySid(CountryRecord.sid);

            if (idx < 0)
            {
                throw new Exception("CountryRecord not found");
            }
            _workbookRecordList.Add(idx + 1, _externSheetRecord);
            _workbookRecordList.Add(idx + 1, supbook);
        }
Exemplo n.º 3
0
        //private static POILogger log = POILogFactory.GetLogger(typeof(Workbook));

        /**
         * Creates new Workbook with no intitialization --useless right now
         * @see #CreateWorkbook(List)
         */
        public InternalWorkbook()
        {
            records = new WorkbookRecordList();

            boundsheets = new List<BoundSheetRecord>();
            formats = new List<FormatRecord>();
            hyperlinks = new List<HyperlinkRecord>();
            numxfs = 0;
            numfonts = 0;
            maxformatid = -1;
            uses1904datewindowing = false;
            escherBSERecords = new List<EscherBSERecord>();
            commentRecords = new Dictionary<String, NameCommentRecord>();
        }
Exemplo n.º 4
0
        public void TestAddNameX()
        {
            WorkbookRecordList wrl = new WorkbookRecordList();
            wrl.Add(0, new BOFRecord());
            wrl.Add(1, new CountryRecord());
            wrl.Add(2, EOFRecord.instance);

            int numberOfSheets = 3;
            LinkTable tbl = new LinkTable(numberOfSheets, wrl);
            // creation of a new LinkTable insert two new records: SupBookRecord followed by ExternSheetRecord
            // assure they are in place:
            //    [BOFRecord]
            //    [CountryRecord]
            //    [SUPBOOK Internal References  nSheets= 3]
            //    [EXTERNSHEET]
            //    [EOFRecord]

            Assert.AreEqual(5, wrl.Records.Count);
            Assert.IsTrue(wrl[(2)] is SupBookRecord);
            SupBookRecord sup1 = (SupBookRecord)wrl[(2)];
            Assert.AreEqual(numberOfSheets, sup1.NumberOfSheets);
            Assert.IsTrue(wrl[(3)] is ExternSheetRecord);
            ExternSheetRecord extSheet = (ExternSheetRecord)wrl[(3)];
            Assert.AreEqual(0, extSheet.NumOfRefs);

            Assert.IsNull(tbl.GetNameXPtg("ISODD", -1));
            Assert.AreEqual(5, wrl.Records.Count); //still have five records

            NameXPtg namex1 = tbl.AddNameXPtg("ISODD");  // Adds two new rercords
            Assert.AreEqual(0, namex1.SheetRefIndex);
            Assert.AreEqual(0, namex1.NameIndex);
            Assert.AreEqual(namex1.ToString(), tbl.GetNameXPtg("ISODD", -1).ToString());

            // Can only find on the right sheet ref, if restricting
            Assert.AreEqual(namex1.ToString(), tbl.GetNameXPtg("ISODD", 0).ToString());
            Assert.IsNull(tbl.GetNameXPtg("ISODD", 1));
            Assert.IsNull(tbl.GetNameXPtg("ISODD", 2));
            // assure they are in place:
            //    [BOFRecord]
            //    [CountryRecord]
            //    [SUPBOOK Internal References  nSheets= 3]
            //    [SUPBOOK Add-In Functions nSheets= 1]
            //    [EXTERNALNAME .name    = ISODD]
            //    [EXTERNSHEET]
            //    [EOFRecord]

            Assert.AreEqual(7, wrl.Records.Count);
            Assert.IsTrue(wrl[(3)] is SupBookRecord);
            SupBookRecord sup2 = (SupBookRecord)wrl[(3)];
            Assert.IsTrue(sup2.IsAddInFunctions);
            Assert.IsTrue(wrl[(4)] is ExternalNameRecord);
            ExternalNameRecord ext1 = (ExternalNameRecord)wrl[(4)];
            Assert.AreEqual("ISODD", ext1.Text);
            Assert.IsTrue(wrl[(5)] is ExternSheetRecord);
            Assert.AreEqual(1, extSheet.NumOfRefs);

            //check that
            Assert.AreEqual(0, tbl.ResolveNameXIx(namex1.SheetRefIndex, namex1.NameIndex));
            Assert.AreEqual("ISODD", tbl.ResolveNameXText(namex1.SheetRefIndex, namex1.NameIndex, null));

            Assert.IsNull(tbl.GetNameXPtg("ISEVEN", -1));
            NameXPtg namex2 = tbl.AddNameXPtg("ISEVEN");  // Adds two new rercords
            Assert.AreEqual(0, namex2.SheetRefIndex);
            Assert.AreEqual(1, namex2.NameIndex);  // name index increased by one
            Assert.AreEqual(namex2.ToString(), tbl.GetNameXPtg("ISEVEN", -1).ToString());
            Assert.AreEqual(8, wrl.Records.Count);
            // assure they are in place:
            //    [BOFRecord]
            //    [CountryRecord]
            //    [SUPBOOK Internal References  nSheets= 3]
            //    [SUPBOOK Add-In Functions nSheets= 1]
            //    [EXTERNALNAME .name    = ISODD]
            //    [EXTERNALNAME .name    = ISEVEN]
            //    [EXTERNSHEET]
            //    [EOFRecord]
            Assert.IsTrue(wrl[(3)] is SupBookRecord);
            Assert.IsTrue(wrl[(4)] is ExternalNameRecord);
            Assert.IsTrue(wrl[(5)] is ExternalNameRecord);
            Assert.AreEqual("ISODD", ((ExternalNameRecord)wrl[(4)]).Text);
            Assert.AreEqual("ISEVEN", ((ExternalNameRecord)wrl[(5)]).Text);
            Assert.IsTrue(wrl[(6)] is ExternSheetRecord);
            Assert.IsTrue(wrl[(7)] is EOFRecord);

            Assert.AreEqual(0, tbl.ResolveNameXIx(namex2.SheetRefIndex, namex2.NameIndex));
            Assert.AreEqual("ISEVEN", tbl.ResolveNameXText(namex2.SheetRefIndex, namex2.NameIndex, null));

        }
Exemplo n.º 5
0
        public void TestNameCommentRecordBetweenNameRecords()
        {

            Record[] recs = {
            new NameRecord(),
            new NameCommentRecord("name1", "comment1"),
            new NameRecord(),
            new NameCommentRecord("name2", "comment2"),

            };
            List<Record> recList = new List<Record>(recs);
            WorkbookRecordList wrl = new WorkbookRecordList();
            Dictionary<String, NameCommentRecord> commentRecords = new Dictionary<String, NameCommentRecord>();

            LinkTable lt = new LinkTable(recList, 0, wrl, commentRecords);
            Assert.IsNotNull(lt);

            Assert.AreEqual(2, commentRecords.Count);
            Assert.IsTrue(recs[1] == commentRecords["name1"]); //== is intentionally not .Equals()!
            Assert.IsTrue(recs[3] == commentRecords["name2"]); //== is intentionally not .Equals()!

            Assert.AreEqual(2, lt.NumNames);
        }
Exemplo n.º 6
0
        public void TestMissingExternSheetRecord_bug47001b()
        {

            Record[] recs = {
                SupBookRecord.CreateAddInFunctions(),
                new SSTRecord(),
        };
            List<Record> recList = new List<Record>(recs);
            WorkbookRecordList wrl = new WorkbookRecordList();

            LinkTable lt;
            try
            {
                lt = new LinkTable(recList, 0, wrl, new Dictionary<String, NameCommentRecord>());
            }
            catch (Exception e)
            {
                if (e.Message.Equals("Expected an EXTERNSHEET record but got (NPOI.HSSF.record.SSTRecord)"))
                {
                    throw new AssertionException("Identified bug 47001b");
                }

                throw e;
            }
            Assert.IsNotNull(lt);
        }
Exemplo n.º 7
0
        public LinkTable(int numberOfSheets, WorkbookRecordList workbookRecordList)
        {
            _workbookRecordList = workbookRecordList;
            _definedNames = new List<NameRecord>();
            _externalBookBlocks = new ExternalBookBlock[] {
                new ExternalBookBlock(numberOfSheets),
            };
            _externSheetRecord = new ExternSheetRecord();
            _recordCount = 2;

            // tell _workbookRecordList about the 2 new records

            SupBookRecord supbook = _externalBookBlocks[0].GetExternalBookRecord();

            int idx = FindFirstRecordLocBySid(CountryRecord.sid);
            if (idx < 0)
            {
                throw new Exception("CountryRecord not found");
            }
            _workbookRecordList.Add(idx + 1, _externSheetRecord);
            _workbookRecordList.Add(idx + 1, supbook);
        }
Exemplo n.º 8
0
        private WorkbookRecordList _workbookRecordList; // TODO - would be nice to Remove this

        public LinkTable(List<Record> inputList, int startIndex, WorkbookRecordList workbookRecordList, Dictionary<String, NameCommentRecord> commentRecords)
        {

            _workbookRecordList = workbookRecordList;
            RecordStream rs = new RecordStream(inputList, startIndex);

            ArrayList temp = new ArrayList();
            while (rs.PeekNextClass() == typeof(SupBookRecord))
            {
                temp.Add(new ExternalBookBlock(rs));
            }

            //_externalBookBlocks = new ExternalBookBlock[temp.Count];
            _externalBookBlocks = (ExternalBookBlock[])temp.ToArray(typeof(ExternalBookBlock));
            temp.Clear();

            if (_externalBookBlocks.Length > 0)
            {
                // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
                if (rs.PeekNextClass() != typeof(ExternSheetRecord))
                {
                    // not quite - if written by google docs
                    _externSheetRecord = null;
                }
                else
                {
                    _externSheetRecord = ReadExtSheetRecord(rs);
                }
            }
            else
            {
                _externSheetRecord = null;
            }

            _definedNames = new List<NameRecord>();
            // collect zero or more DEFINEDNAMEs id=0x18
            while (true)
            {

                Type nextClass = rs.PeekNextClass();
                if (nextClass == typeof(NameRecord))
                {
                    NameRecord nr = (NameRecord)rs.GetNext();
                    _definedNames.Add(nr);
                }
                else if (nextClass == typeof(NameCommentRecord))
                {
                    NameCommentRecord ncr = (NameCommentRecord)rs.GetNext();
                    //commentRecords.Add(ncr.NameText, ncr);
                    commentRecords[ncr.NameText] = ncr;
                }
                else
                {
                    break;
                }
            }

            _recordCount = rs.GetCountRead();
            for (int i = startIndex; i < startIndex + _recordCount; i++)
            {
                _workbookRecordList.Records.Add(inputList[i]);
            }

        }
Exemplo n.º 9
0
        private WorkbookRecordList _workbookRecordList; // TODO - would be nice to Remove this

        public LinkTable(IList inputList, int startIndex, WorkbookRecordList workbookRecordList)
        {

            _workbookRecordList = workbookRecordList;
            RecordStream rs = new RecordStream(inputList, startIndex);

            ArrayList temp = new ArrayList();
            while (rs.PeekNextClass() == typeof(SupBookRecord))
            {
                temp.Add(new ExternalBookBlock(rs));
            }

            //_externalBookBlocks = new ExternalBookBlock[temp.Count];
            _externalBookBlocks=(ExternalBookBlock[])temp.ToArray(typeof(ExternalBookBlock));
            temp.Clear();

            if (_externalBookBlocks.Length > 0)
            {
                // If any ExternalBookBlock present, there Is always 1 of ExternSheetRecord
                Record next = rs.GetNext();
                _externSheetRecord = (ExternSheetRecord)next;
            }
            else
            {
                _externSheetRecord = null;
            }

            _definedNames = new ArrayList();
            // collect zero or more DEFINEDNAMEs id=0x18
            while (rs.PeekNextClass() == typeof(NameRecord))
            {
                NameRecord nr = (NameRecord)rs.GetNext();
                _definedNames.Add(nr);
            }

            _recordCount = rs.GetCountRead();
            for(int i=startIndex;i< startIndex + _recordCount;i++)
            {
                _workbookRecordList.Records.Add(inputList[i]);
            }
            
        }