public static string ToHexDumpString(this BiffRecord record, int maxLength = 0x10, bool showAttrInfo = false) { string biffString = record.ToString(); //Skip the 4 byte header byte[] bytes = record.GetBytes().Skip(4).ToArray(); string hexDumpString = HexDump(bytes); if (record is Formula) { biffString = ((Formula)record).ToFormulaString(showAttrInfo); } else if (record.Id == RecordType.Dimensions) { biffString = record.AsRecordType <Dimensions>().ToString(); } else if (record.Id == RecordType.Lbl) { biffString = ((Lbl)record).ToString(); } if ((bytes.Length <= maxLength && bytes.Length > 0) || record.Id == RecordType.Obj) { biffString += "\n" + hexDumpString; } return(biffString); }
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); }
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); }
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 ((bytes.Length <= maxLength && bytes.Length > 0) || record.Id == RecordType.Obj) { biffString += "\n" + hexDumpString; } return(biffString); }
public static T AsRecordType <T>(this BiffRecord record) where T : BiffRecord { byte[] recordBytes = record.GetBytes(); using (MemoryStream ms = new MemoryStream(recordBytes)) { VirtualStreamReader vsr = new VirtualStreamReader(ms); RecordType id = (RecordType)vsr.ReadUInt16(); ushort len = vsr.ReadUInt16(); var typeConstructor = typeof(T).GetConstructor(new Type[] { typeof(IStreamReader), typeof(RecordType), typeof(ushort) }); if (typeConstructor == null) { throw new ArgumentException(string.Format("Could not find appropriate constructor for type {0}", typeof(T).FullName)); } return((T)typeConstructor.Invoke(new object[] { vsr, id, len })); } }