public override byte[] GetBytes() { using (BinaryWriter bw = new BinaryWriter(new MemoryStream())) { bw.Write(GetHeaderBytes()); bw.Write(Convert.ToUInt16(this.ctab)); bw.Write(Convert.ToUInt16(this.cch)); if (this.isvirtpath && this.ctab == 1 && this.cch < 0xff) { XLUnicodeStringNoCch virtPathXLU = new XLUnicodeStringNoCch(virtpathstring); bw.Write(virtPathXLU.Bytes); foreach (var rgstString in this.rgst) { ushort length = Convert.ToUInt16(rgstString.Length); bw.Write(length); XLUnicodeStringNoCch rgstXLU = new XLUnicodeStringNoCch(rgstString); bw.Write(rgstXLU.Bytes); } } else if (this.isvirtpath || this.isexternalworkbookreferencing || this.isunusedsupportinglink) { throw new NotImplementedException(); } return(bw.GetBytesWritten()); } }
public Lbl(IStreamReader reader, RecordType id, ushort length) : base(reader, id, length) { // assert that the correct record type is instantiated //Debug.Assert(this.Id == ID); ushort flags = reader.ReadUInt16(); this.fHidden = Utils.BitmaskToBool(flags, 0x0001); this.fFunc = Utils.BitmaskToBool(flags, 0x0002); this.fOB = Utils.BitmaskToBool(flags, 0x0004); this.fProc = Utils.BitmaskToBool(flags, 0x0008); this.fCalcExp = Utils.BitmaskToBool(flags, 0x0010); this.fBuiltin = Utils.BitmaskToBool(flags, 0x0020); this.fGrp = Utils.BitmaskToByte(flags, 0x0FC0); this.fReserved1 = Utils.BitmaskToBool(flags, 0x1000); this.fPublished = Utils.BitmaskToBool(flags, 0x2000); this.fWorkbookParam = Utils.BitmaskToBool(flags, 0x4000); this.fReserved2 = Utils.BitmaskToBool(flags, 0x8000); this.chKey = reader.ReadByte(); this.cch = reader.ReadByte(); this.cce = reader.ReadUInt16(); //read 2 reserved bytes this.fReserved3 = reader.ReadUInt16(); this.itab = reader.ReadUInt16(); // read 4 reserved bytes this.fReserved4 = reader.ReadUInt32(); if (this.cch > 0) { _name = new XLUnicodeStringNoCch(reader, this.cch); } else { _name = new XLUnicodeStringNoCch(); } long oldStreamPosition = this.Reader.BaseStream.Position; try { _rgce = ExcelHelperClass.getFormulaStack(this.Reader, this.cce); } catch (Exception ex) { this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin); this.Reader.BaseStream.Seek(this.cce, System.IO.SeekOrigin.Current); TraceLogger.Error("Formula parse error in intern name"); TraceLogger.Debug(ex.StackTrace); } // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
public SXViewLink(IStreamReader reader, RecordType id, ushort length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); this.rt = reader.ReadUInt16(); //unused / reserved reader.ReadBytes(4); this.cch = reader.ReadByte(); if (this.cch > 0) { this.XLUnicodeStringNoCch = new XLUnicodeStringNoCch(reader, this.cch); } // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
public Lbl(IStreamReader reader, RecordType id, ushort length) : base(reader, id, length) { // assert that the correct record type is instantiated //Debug.Assert(this.Id == ID); ushort flags = reader.ReadUInt16(); this.fHidden = Utils.BitmaskToBool(flags, 0x0001); this.fFunc = Utils.BitmaskToBool(flags, 0x0002); this.fOB = Utils.BitmaskToBool(flags, 0x0004); this.fProc = Utils.BitmaskToBool(flags, 0x0008); this.fCalcExp = Utils.BitmaskToBool(flags, 0x0010); this.fBuiltin = Utils.BitmaskToBool(flags, 0x0020); this.fGrp = Utils.BitmaskToByte(flags, 0x0FC0); this.fReserved1 = Utils.BitmaskToBool(flags, 0x1000); this.fPublished = Utils.BitmaskToBool(flags, 0x2000); this.fWorkbookParam = Utils.BitmaskToBool(flags, 0x4000); this.fReserved2 = Utils.BitmaskToBool(flags, 0x8000); this.chKey = reader.ReadByte(); this.cch = reader.ReadByte(); this.cce = reader.ReadUInt16(); //read 2 reserved bytes this.fReserved3 = reader.ReadUInt16(); this.itab = reader.ReadUInt16(); // read 4 reserved bytes this.fReserved4 = reader.ReadUInt32(); //Peek at the fHighByte value to figure out if the Lbl is encrypted or not long oldStreamPosition = this.Reader.BaseStream.Position; bool fHighByte = Utils.BitmaskToBool(reader.ReadByte(), 0x0001); this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin); //If a lbl has garbage cce/cch values, ignore reading those values if (this.Length != CalculateLength(fHighByte)) { this.RawLblBytes = this.Reader.ReadBytes((int)(this.Length - LblFixedSize)); _name = new XLUnicodeStringNoCch(); _rgce = new Stack <AbstractPtg>(); return; } if (this.cch > 0) { _name = new XLUnicodeStringNoCch(reader, this.cch); } else { _name = new XLUnicodeStringNoCch(); } oldStreamPosition = this.Reader.BaseStream.Position; try { _rgce = ExcelHelperClass.getFormulaStack(this.Reader, this.cce); } catch (Exception ex) { this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin); this.Reader.BaseStream.Seek(this.cce, System.IO.SeekOrigin.Current); TraceLogger.Error("Formula parse error in intern name"); TraceLogger.Debug(ex.StackTrace); } // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
public void SetName(XLUnicodeStringNoCch name) { _name = name; cch = (byte)name.Value.Length; _length = CalculateLength(); }
public TxO(IStreamReader reader, RecordType id, UInt16 length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); long startPosition = this.Reader.BaseStream.Position; // NOTE: controlInfo is an option field that exists if and only if the value of // cmo.ot in the preceding Obj record is 0, 5, 7, 11, 12 or 14. // However, the current parser implementation does not allow us to see the preceding // record(s) witout an enormous recactoring. Therefore we're a little bit hacky here // and try to read the record first without the optional field. If we didn't succeed // we start a second try, this time including the optional field. // for (int noOfTries = 1; noOfTries < 3; noOfTries++) { // initialize class members from stream UInt16 flags = reader.ReadUInt16(); this.hAlignment = (HorizontalAlignment)Utils.BitmaskToInt(flags, 0xE); this.vAlignment = (VerticalAlignment)Utils.BitmaskToInt(flags, 0x70); this.rot = (TextRotation)reader.ReadUInt16(); reader.ReadBytes(6); // reserved // read optional field controlInfo on second try if (noOfTries == 2) { this.controlInfo = new ControlInfo(reader); } this.cchText = reader.ReadUInt16(); this.cbRuns = reader.ReadUInt16(); this.ifntEmpty = reader.ReadUInt16(); this.fmla = new ObjFmla(reader); if (this.Offset + this.Length == this.Reader.BaseStream.Position) { break; } else if (noOfTries == 1) { // re-read record, this time including the optional controlInfo field this.Reader.BaseStream.Position = startPosition; } } // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); // NOTE: If the field cchText is not zero, this record doesn‘t fully specify the text. // The rest of the data that MUST be specified is the text string and the formatting runs // information. // if (this.cchText > 0 && BiffRecord.GetNextRecordType(reader) == RecordType.Continue) { // skip record header reader.ReadUInt16(); reader.ReadUInt16(); this.text = new XLUnicodeStringNoCch(reader, this.cchText); if (BiffRecord.GetNextRecordType(reader) == RecordType.Continue) { // skip record header reader.ReadUInt16(); reader.ReadUInt16(); this.runs = new TxORuns(reader, this.cbRuns); } } }