예제 #1
0
        public static string ToHexDumpString(this BiffRecord record, int maxLength = 0x10)
        {
            string biffString = record.ToString();

            //Skip the 4 byte header
            byte[] bytes         = record.GetBytes().Skip(4).ToArray();
            string hexDumpString = HexDump(bytes);

            if (record.Id == RecordType.Formula)
            {
                biffString = record.AsRecordType <Formula>().ToString();
            }
            else if (record.Id == RecordType.Dimensions)
            {
                biffString = record.AsRecordType <Dimensions>().ToString();
            }
            else if (record.Id == RecordType.Lbl)
            {
                biffString = record.AsRecordType <Lbl>().ToString();
            }


            if ((bytes.Length <= maxLength && bytes.Length > 0) ||
                record.Id == RecordType.Obj)
            {
                biffString += "\n" + hexDumpString;
            }

            return(biffString);
        }
예제 #2
0
        public static string ToHexDumpString(this BiffRecord record, int maxLength = 0x10, bool showAttrInfo = false, bool includeHeader = false)
        {
            string biffString = record.ToString();

            byte[] bytes = record.GetBytes();

            //Skip the 4 byte header if we aren't including the header
            if (includeHeader == false)
            {
                bytes = bytes.Skip(4).ToArray();
            }

            string hexDumpString = HexDump(bytes);

            if (record is Formula)
            {
                Formula f = (Formula)record;
                if (f.cce == 0 && f.RawBytesValue.Length != bytes.Length + 4)
                {
                    biffString = "!Error Parsing Formula!";
                }
                else
                {
                    biffString = f.ToFormulaString(showAttrInfo);
                }
            }
            else if (record.Id == RecordType.Dimensions)
            {
                biffString = record.AsRecordType <Dimensions>().ToString();
            }
            else if (record.Id == RecordType.Lbl)
            {
                try
                {
                    biffString = record.AsRecordType <Lbl>().ToString();
                }
                catch (Exception e)
                {
                    biffString = record.ToString();
                }
            }


            if ((bytes.Length <= maxLength && bytes.Length > 0) ||
                record.Id == RecordType.Obj)
            {
                biffString += "\n" + hexDumpString;
            }

            return(biffString);
        }
예제 #3
0
        public static List <BiffRecord> UpdateGlobalsStreamReferences(List <BiffRecord> records)
        {
            List <Lbl>         labelRecords = records.Where(r => r.Id == RecordType.Lbl).Select(r => r.AsRecordType <Lbl>()).ToList();
            List <BoundSheet8> sheetRecords = records.Where(r => r.Id == RecordType.BoundSheet8).Select(r => r.AsRecordType <BoundSheet8>()).ToList();
            //Incorrect way to do this, but works for simpler cases - just pull the first ExternSheet record in the XLS file.
            BiffRecord firstExternSheet = records.FirstOrDefault(r => r.Id == RecordType.ExternSheet);

            List <BiffRecord> updatedRecords = new List <BiffRecord>();

            foreach (var record in records)
            {
                switch (record)
                {
                case Formula formulaRecord:
                    Stack <AbstractPtg> modifiedFormulaStack = UpdateNameRecords(formulaRecord.ptgStack, labelRecords);
                    if (firstExternSheet != null)
                    {
                        modifiedFormulaStack = UpdateSheetReferences(modifiedFormulaStack, sheetRecords,
                                                                     firstExternSheet.AsRecordType <ExternSheet>());
                    }
                    formulaRecord.SetCellParsedFormula(new CellParsedFormula(modifiedFormulaStack));
                    updatedRecords.Add(formulaRecord);
                    continue;

                case Lbl lblRecord:
                    Stack <AbstractPtg> modifiedLabelStack = UpdateNameRecords(lblRecord.rgce, labelRecords);
                    if (firstExternSheet != null)
                    {
                        modifiedLabelStack = UpdateSheetReferences(modifiedLabelStack, sheetRecords,
                                                                   firstExternSheet.AsRecordType <ExternSheet>());
                    }
                    lblRecord.SetRgce(modifiedLabelStack);
                    updatedRecords.Add(lblRecord);
                    continue;

                default:
                    updatedRecords.Add(record);
                    continue;
                }
            }
            return(updatedRecords);
        }
예제 #4
0
        public void TestBiffRecordCloneAndGetBytes()
        {
            BoundSheet8 bs8 = new BoundSheet8(BoundSheet8.HiddenState.Visible, BoundSheet8.SheetType.Worksheet, "MySheetName");

            byte[]     bs8bytes       = bs8.GetBytes();
            BiffRecord bs8CloneRecord = (BiffRecord)bs8.Clone();

            byte[] bs8cloneBytes = bs8CloneRecord.GetBytes();
            Assert.AreEqual(bs8bytes, bs8cloneBytes);
            BoundSheet8 bs8Clone = bs8CloneRecord.AsRecordType <BoundSheet8>();

            byte[] bs8asRecordBytes = bs8Clone.GetBytes();
            Assert.AreEqual(bs8bytes, bs8asRecordBytes);
        }
예제 #5
0
        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);
        }