using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using Biff8Excel.Interfaces; namespace Biff8Excel.Records { [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)] struct RecordBoundSheet { public ushort opcode; // 0x85; public ushort length; public uint streamPosition; [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte visibility; [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte sheetType; // = 0x0; [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte namelength; [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte zero; // Unicode flag (compressed String) } internal class BoundSheet : IRecords { RecordBoundSheet boundsheet; string sheetName; byte[] sheetNameBytes; ushort recLen; public BoundSheet() { boundsheet.opcode = 0x85; boundsheet.sheetType = 0x0; boundsheet.zero = 0x0; } internal ushort ID { get{ return boundsheet.opcode ;} } internal ushort RecordSize { get { return recLen; } } internal uint StreamPosition { set {boundsheet.streamPosition = value;} } internal string StreamName { set { sheetName = value; if (sheetName.Length != Globals.GetDefaultBytesLength(sheetName)) { boundsheet.zero = 0x1; sheetNameBytes = Globals.GetUnicodeBytes(sheetName); } else { boundsheet.zero = 0x0; sheetNameBytes = Globals.GetDefaultBytes(sheetName); } } } internal byte Visible { set {boundsheet.visibility |= value;} } #region IRecords 成员 public byte[] GetByte() { byte[] b; if (sheetName == null) throw new Biff8ExcelException("请先设定sheetName"); //recLen = (ushort)(sheetName.Length + 12); //recLen = (ushort)(Globals.GetUnicodeByteLength(sheetName) + 12); recLen = (ushort)(sheetNameBytes.Length + 12); b = new byte[recLen]; boundsheet.length = (ushort)(b.Length - 4); //boundsheet.namelength = (byte)(Globals.GetByteLength(sheetName)); boundsheet.namelength = (byte)sheetName.Length; Globals.GetStructToBytes(boundsheet).CopyTo(b, 0); //Globals.GetBytes(sheetName).CopyTo(b, 12); //Globals.GetUnicodeBytes(sheetName).CopyTo(b, 12); sheetNameBytes.CopyTo(b, 12); return b; } #endregion } }