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 RecordDBCell { public ushort opcode; public ushort length; public uint RowOffset; } public class DBCell : IRecords { RecordDBCell dbcell; int m_NumberOfCellOffsets; const int STRUCT_DBCELL_LENGTH = 8; // ushort 2 + ushort 2 + uint 4 = 8 int[] m_CellOffset; //List m_CellOffset; public DBCell() { dbcell.opcode = 0xD7; } public ushort Id { get {return dbcell.opcode ;} } public ushort RecordSize { get { return (ushort)(STRUCT_DBCELL_LENGTH + (m_NumberOfCellOffsets * 4)); } } public int[] CellOffsets //public List CellOffsets { internal set { m_NumberOfCellOffsets = value.Length; //m_NumberOfCellOffsets = value.Count; m_CellOffset = value; } get { return m_CellOffset; } } public uint RowOffset { set {dbcell.RowOffset = value;} get { return dbcell.RowOffset; } } #region IRecords 成员 public byte[] GetByte() { if (m_CellOffset == null) throw new Biff8ExcelException("先设定CellOffsets"); byte[] tmp, r; int ln = STRUCT_DBCELL_LENGTH + (2 * m_NumberOfCellOffsets); r = new byte[ln]; dbcell.length = (ushort)(ln - 4); tmp = Globals.GetStructToBytes(dbcell); tmp.CopyTo(r, 0); int pos = 8; //for (int i = 0; i < m_CellOffset.Length; i++, pos += 2) for (int i = 0; i < m_CellOffset.Length ; i++, pos += 2) { tmp = BitConverter.GetBytes(m_CellOffset[i]); Array.Copy(tmp, 0, r, pos, 2); //BitConverter.GetBytes( m_CellOffset[i]).CopyTo( r,pos); } return r; } #endregion } }