/// <summary> /// extracts the boundsheetdata from the biffrecord /// </summary> /// <param name="reader">IStreamReader </param> /// <param name="id">Type of the record </param> /// <param name="length">Length of the record</param> public BoundSheet8(IStreamReader reader, RecordType id, ushort length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); this.lbPlyPos = this.Reader.ReadUInt32(); byte flags = reader.ReadByte(); Flags = flags; // Bitmask is 0003h -> first two bits, but we can hide our hidden status by flipping reserved bits this.hsState = (HiddenState)Utils.BitmaskToByte(flags, 0x00FF); this.dt = (SheetType)reader.ReadByte(); this.stName = new ShortXLUnicodeString(reader); if (this.Offset + this.Length != this.Reader.BaseStream.Position) { Console.WriteLine("BoundSheet8 Record is malformed - document probably has a password"); throw new Exception("BoundSheet8 Record is malformed - document probably has a password"); } // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
public Font(IStreamReader reader, RecordType id, UInt16 length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); // initialize class members from stream this.dyHeight = reader.ReadUInt16(); UInt16 flags = reader.ReadUInt16(); // 0x0001 is unused this.fItalic = Utils.BitmaskToBool(flags, 0x0002); // 0x0004 is unused this.fStrikeOut = Utils.BitmaskToBool(flags, 0x0008); this.fOutline = Utils.BitmaskToBool(flags, 0x0010); this.fShadow = Utils.BitmaskToBool(flags, 0x0020); this.fCondense = Utils.BitmaskToBool(flags, 0x0040); this.fExtend = Utils.BitmaskToBool(flags, 0x0080); this.icv = reader.ReadUInt16(); this.bls = (FontWeight)reader.ReadUInt16(); this.sss = (ScriptStyle)reader.ReadUInt16(); this.uls = (UnderlineStyle)reader.ReadByte(); this.bFamily = (FontFamily)reader.ReadByte(); this.bCharSet = reader.ReadByte(); // skip unused byte reader.ReadByte(); this.fontName = new ShortXLUnicodeString(reader); // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
public BoundSheet8(HiddenState hsState, SheetType dt, string sheetName) : base(RecordType.BoundSheet8, 0) { this.hsState = hsState; this.dt = dt; stName = new ShortXLUnicodeString(sheetName, false); //lbPlyPos (4) hsState (1) dt (1) stName.cch (1) stName.fHighByte (1) + stName.rgb (strlen) this._length = (uint)(8 + sheetName.Length); }
public SeriesText(IStreamReader reader, RecordType id, UInt16 length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); // initialize class members from stream reader.ReadBytes(2); // reserved this.stText = new ShortXLUnicodeString(reader); // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
public PtgStr(IStreamReader reader, PtgNumber ptgid) : base(reader, ptgid) { Debug.Assert(this.Id == ID); this.type = PtgType.Operand; this.popSize = 1; var st = new ShortXLUnicodeString(this.Reader); // quotes need to be escaped this.Data = ExcelHelperClass.EscapeFormulaString(st.Value); this.Length = (uint)(3 + st.rgb.Length); // length = 1 byte Ptgtype + 1byte cch + 1byte highbyte }
/// <summary> /// extracts the boundsheetdata from the biffrecord /// </summary> /// <param name="reader">IStreamReader </param> /// <param name="id">Type of the record </param> /// <param name="length">Length of the record</param> public BoundSheet8(IStreamReader reader, RecordType id, ushort length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); this.lbPlyPos = this.Reader.ReadUInt32(); byte flags = reader.ReadByte(); Flags = flags; // Bitmask is 0003h -> first two bits, but we can hide our hidden status by flipping reserved bits this.hsState = (HiddenState)Utils.BitmaskToByte(flags, 0x00FF); this.dt = (SheetType)reader.ReadByte(); var oldStreamPosition = this.Reader.BaseStream.Position; var cch = reader.ReadByte(); var fHighByte = Utils.BitmaskToBool(reader.ReadByte(), 0x0001); this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin); if ((fHighByte && (this.Length - 8 != cch * 2)) || (!fHighByte && (this.Length - 8 != cch))) { //BoundSheet8 Record is Encrypted - just read the bytes, don't process them //don't grab lbPlyPos, dt, and hsState (6 bytes), but grab everything else this.RawSheetNameBytes = reader.ReadBytes((int)(this.Length - 6)); return; } else { this.stName = new ShortXLUnicodeString(reader); } if (this.Offset + this.Length != this.Reader.BaseStream.Position) { Console.WriteLine("BoundSheet8 Record is malformed - document probably has a password"); throw new Exception("BoundSheet8 Record is malformed - document probably has a password"); } // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
/// <summary> /// extracts the boundsheetdata from the biffrecord /// </summary> /// <param name="reader">IStreamReader </param> /// <param name="id">Type of the record </param> /// <param name="length">Length of the record</param> public BoundSheet8(IStreamReader reader, RecordType id, ushort length) : base(reader, id, length) { // assert that the correct record type is instantiated Debug.Assert(this.Id == ID); this.lbPlyPos = this.Reader.ReadUInt32(); byte flags = reader.ReadByte(); // Bitmask is 0003h -> first two bits this.hsState = (HiddenState)Utils.BitmaskToByte(flags, 0x0003); this.dt = (SheetType)reader.ReadByte(); this.stName = new ShortXLUnicodeString(reader); // assert that the correct number of bytes has been read from the stream Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position); }
private static byte[] GetByteDataFromPtg(AbstractPtg ptg) { MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); switch (ptg) { case PtgInt ptgInt: bw.Write(Convert.ToUInt16(ptg.getData())); break; case PtgArray ptgArray: bw.Write(ptgArray.DataBytes); break; case PtgAdd ptgAdd: case PtgSub ptgSub: case PtgMul ptgMul: case PtgDiv ptgDiv: case PtgParen ptgParen: case PtgPower ptgPower: case PtgPercent ptgPercent: case PtgGt ptgGt: case PtgGe ptgGe: case PtgLt ptgLt: case PtgLe ptgLe: case PtgEq ptgEq: case PtgNe ptgNe: case PtgUminus ptgUminus: case PtgUplus ptgUplus: case PtgConcat ptgConcat: case PtgUnion ptgUnion: case PtgIsect ptgIsect: case PtgMissArg ptgMissArg: //No Data break; case PtgNum ptgNum: bw.Write(Convert.ToDouble(ptg.getData(), CultureInfo.GetCultureInfo("en-US"))); break; case PtgRef ptgRef: RgceLoc loc = new RgceLoc(ptgRef.rw, ptgRef.col, ptgRef.colRelative, ptgRef.rwRelative); bw.Write(loc.Bytes); break; case PtgRefN ptgRefN: RgceLoc loc2 = new RgceLoc(Convert.ToUInt16(ptgRefN.rw), Convert.ToUInt16(ptgRefN.col), ptgRefN.colRelative, ptgRefN.rwRelative); bw.Write(loc2.Bytes); break; case PtgBool ptgBool: string boolData = ptgBool.getData(); bw.Write((boolData.Equals("TRUE") ? (byte)1 : (byte)0)); break; case PtgStr ptgStr: string unescapedString = ExcelHelperClass.UnescapeFormulaString(ptgStr.getData()); ShortXLUnicodeString ptgString = new ShortXLUnicodeString(unescapedString, ptgStr.isUnicode); bw.Write(ptgString.Bytes); break; case PtgFuncVar ptgFuncVar: bw.Write(ptgFuncVar.cparams); ushort tab = ptgFuncVar.tab; ushort fCeFunc = ptgFuncVar.fCelFunc ? (ushort)0x8000 : (ushort)0; tab = (ushort)(tab | fCeFunc); bw.Write(tab); break; case PtgFunc ptgFunc: bw.Write(Convert.ToUInt16(ptgFunc.tab)); break; case PtgExp ptgExp: RgceLoc loc3 = new RgceLoc(Convert.ToUInt16(ptgExp.rw), Convert.ToUInt16(ptgExp.col), false, false); bw.Write(loc3.Bytes); break; case PtgRef3d ptgRef3d: RgceLoc loc4 = new RgceLoc(Convert.ToUInt16(ptgRef3d.rw), Convert.ToUInt16(ptgRef3d.col), ptgRef3d.colRelative, ptgRef3d.rwRelative); bw.Write(Convert.ToUInt16(ptgRef3d.ixti)); bw.Write(loc4.Bytes); break; case PtgAttrBaxcel ptgAttrBaxcel: bw.Write(ptgAttrBaxcel.DataBytes); break; case PtgAttrIf ptgAttrIf: bw.Write(ptgAttrIf.Offset); break; case PtgAttrGoto ptgAttrGoto: bw.Write(ptgAttrGoto.Offset); break; case PtgAttrSpace ptgAttrSpace: bw.Write(ptgAttrSpace.PtgAttrSpaceType); break; case PtgName ptgName: bw.Write(ptgName.nameindex); break; case PtgArea ptgArea: bw.Write(ptgArea.rwFirst); bw.Write(ptgArea.rwLast); bw.Write(ptgArea.colFirst); bw.Write(ptgArea.colLast); break; case PtgErr ptgErr: bw.Write(ptgErr.Err); break; case PtgAttrSum ptgAttrSum: //Start 0x19 ## Section case PtgAttrSemi ptgAttrSemi: case PtgAttrChoose ptgAttrChoose: case PtgNotDocumented ptgNotDocumented: case PtgMemErr ptgMemErr: case PtgAreaN ptgAreaN: case PtgArea3d ptgArea3d: case PtgNameX ptgNameX: case PtgRefErr ptgRefErr: case PtgRefErr3d ptgRefErr3d: case PtgAreaErr ptgAreaErr: case PtgAreaErr3d ptgAreaErr3d: case PtgMemFunc ptgMemFunc: default: throw new NotImplementedException(string.Format("No byte conversion implemented for {0}", ptg)); } return(bw.GetBytesWritten()); }