コード例 #1
0
        public void AddName(NameRecord name)
        {
            _definedNames.Add(name);

            // TODO - this Is messy
            // Not the most efficient way but the other way was causing too many bugs
            int idx = FindFirstRecordLocBySid(ExternSheetRecord.sid);

            if (idx == -1)
            {
                idx = FindFirstRecordLocBySid(SupBookRecord.sid);
            }
            if (idx == -1)
            {
                idx = FindFirstRecordLocBySid(CountryRecord.sid);
            }
            int countNames = _definedNames.Count;

            _workbookRecordList.Add(idx + countNames, name);
        }
コード例 #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);
        }
コード例 #3
0
ファイル: TestLinkTable.cs プロジェクト: Reinakumiko/npoi
        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));

        }
コード例 #4
0
ファイル: LinkTable.cs プロジェクト: Reinakumiko/npoi
        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);
        }