Exemplo n.º 1
0
        public void TestLabelSerialization()
        {
            WorkbookStream macroWorkbookStream = TestHelpers.GetMultiSheetMacroBytes();

            List <SupBook> supBooks = macroWorkbookStream.GetAllRecordsByType <SupBook>();
            List <Lbl>     labels   = macroWorkbookStream.GetAllRecordsByType <Lbl>();

            Lbl lastLabel  = labels.Last();
            Lbl cloneLabel = ((BiffRecord)lastLabel.Clone()).AsRecordType <Lbl>();

            byte[] labelBytes = lastLabel.GetBytes();
            byte[] cloneBytes = cloneLabel.GetBytes();

            Assert.AreEqual(labelBytes, cloneBytes);
        }
Exemplo n.º 2
0
        public void TestChangeLabel()
        {
            WorkbookStream macroWorkbookStream = new WorkbookStream(TestHelpers.GetMacroTestBytes());
            List <Lbl>     labels = macroWorkbookStream.GetAllRecordsByType <Lbl>();

            Lbl autoOpenLbl = labels.First(l => l.fBuiltin && l.Name.Value.Equals("\u0001"));

            Lbl replaceLabelStringLbl = ((BiffRecord)autoOpenLbl.Clone()).AsRecordType <Lbl>();

            replaceLabelStringLbl.SetName(new XLUnicodeStringNoCch("Auto_Open", true));
            replaceLabelStringLbl.fBuiltin = false;

            var cloneLabel  = ((BiffRecord)replaceLabelStringLbl.Clone()).AsRecordType <Lbl>();
            var cBytes      = cloneLabel.GetBytes();
            var rLabelBytes = replaceLabelStringLbl.GetBytes();

            Assert.AreEqual(rLabelBytes, cBytes);
            macroWorkbookStream = macroWorkbookStream.ReplaceRecord(autoOpenLbl, replaceLabelStringLbl);
            macroWorkbookStream = macroWorkbookStream.FixBoundSheetOffsets();

            ExcelDocWriter writer = new ExcelDocWriter();

            writer.WriteDocument(TestHelpers.AssemblyDirectory + Path.DirectorySeparatorChar + "changedLabel.xls", macroWorkbookStream.ToBytes());
        }