Esempio n. 1
0
        public void TestContainsRecord()
        {
            byte[]         wbBytes = TestHelpers.GetTemplateMacroBytes();
            WorkbookStream wbs     = new WorkbookStream(wbBytes);

            BoundSheet8 notContainedRecord = new BoundSheet8(BoundSheet8.HiddenState.Visible, BoundSheet8.SheetType.Worksheet, "MySheetName");
            BoundSheet8 containedRecord    = wbs.GetAllRecordsByType <BoundSheet8>().First();

            Assert.IsTrue(wbs.ContainsRecord(containedRecord));
            Assert.IsFalse(wbs.ContainsRecord(notContainedRecord));
        }
Esempio n. 2
0
        public void TestReplaceRecord()
        {
            byte[]         wbBytes = TestHelpers.GetTemplateMacroBytes();
            WorkbookStream wbs     = new WorkbookStream(wbBytes);

            BoundSheet8 bs8 = new BoundSheet8(BoundSheet8.HiddenState.Visible, BoundSheet8.SheetType.Worksheet, "MySheetName");

            var recordCount = wbs.Records.Count;

            BoundSheet8 oldSheetRecord = wbs.GetAllRecordsByType <BoundSheet8>().First();

            WorkbookStream wbs2 = wbs.ReplaceRecord(oldSheetRecord, bs8);

            Assert.AreEqual(recordCount, wbs2.Records.Count);

            BoundSheet8 newSheetRecord = wbs2.GetAllRecordsByType <BoundSheet8>().First();

            Assert.AreEqual(newSheetRecord.stName.Value, bs8.stName.Value);

            Assert.IsFalse(wbs2.ContainsRecord(oldSheetRecord));
            Assert.IsTrue(wbs2.ContainsRecord(bs8));
        }
        public void TestGetDefaultMacroSheetInternationalized()
        {
            Intl manuallyCreatedIntlRecord = new Intl();

            byte[] intlBytes = manuallyCreatedIntlRecord.GetBytes();

            BiffRecord rec = new BiffRecord(intlBytes);

            Intl convertedRecord = rec.AsRecordType <Intl>();

            Assert.AreEqual(convertedRecord.GetBytes(), manuallyCreatedIntlRecord.GetBytes());

            WorkbookStream    wbs          = TestHelpers.GetDefaultMacroTemplate();
            List <BiffRecord> sheetRecords = wbs.GetRecordsForBOFRecord(wbs.GetAllRecordsByType <BOF>().Last());

            WorkbookStream internationalWbs = new WorkbookStream(sheetRecords);
            var            intlRecord       = new Intl();

            internationalWbs = internationalWbs.InsertRecord(intlRecord, internationalWbs.GetAllRecordsByType <b2xtranslator.Spreadsheet.XlsFileFormat.Records.Index>().First());
            Assert.IsTrue(internationalWbs.ContainsRecord(intlRecord));
            var nextRecord = internationalWbs.Records.SkipWhile(r => r.Id != RecordType.Intl).Skip(1).Take(1).First();

            Assert.IsTrue(nextRecord.Id == RecordType.CalcMode);
        }