DBCell.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. using Biff8Excel.Interfaces;
  6. namespace Biff8Excel.Records
  7. {
  8. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
  9. struct RecordDBCell
  10. {
  11. public ushort opcode;
  12. public ushort length;
  13. public uint RowOffset;
  14. }
  15. public class DBCell : IRecords
  16. {
  17. RecordDBCell dbcell;
  18. int m_NumberOfCellOffsets;
  19. const int STRUCT_DBCELL_LENGTH = 8; // ushort 2 + ushort 2 + uint 4 = 8
  20. int[] m_CellOffset;
  21. //List<int> m_CellOffset;
  22. public DBCell()
  23. {
  24. dbcell.opcode = 0xD7;
  25. }
  26. public ushort Id
  27. {
  28. get {return dbcell.opcode ;}
  29. }
  30. public ushort RecordSize
  31. {
  32. get { return (ushort)(STRUCT_DBCELL_LENGTH + (m_NumberOfCellOffsets * 4)); }
  33. }
  34. public int[] CellOffsets
  35. //public List<int> CellOffsets
  36. {
  37. internal set
  38. {
  39. m_NumberOfCellOffsets = value.Length;
  40. //m_NumberOfCellOffsets = value.Count;
  41. m_CellOffset = value;
  42. }
  43. get { return m_CellOffset; }
  44. }
  45. public uint RowOffset
  46. {
  47. set {dbcell.RowOffset = value;}
  48. get { return dbcell.RowOffset; }
  49. }
  50. #region IRecords ³ÉÔ±
  51. public byte[] GetByte()
  52. {
  53. if (m_CellOffset == null)
  54. throw new Biff8ExcelException("ÏÈÉ趨CellOffsets");
  55. byte[] tmp, r;
  56. int ln = STRUCT_DBCELL_LENGTH + (2 * m_NumberOfCellOffsets);
  57. r = new byte[ln];
  58. dbcell.length = (ushort)(ln - 4);
  59. tmp = Globals.GetStructToBytes(dbcell);
  60. tmp.CopyTo(r, 0);
  61. int pos = 8;
  62. //for (int i = 0; i < m_CellOffset.Length; i++, pos += 2)
  63. for (int i = 0; i < m_CellOffset.Length ; i++, pos += 2)
  64. {
  65. tmp = BitConverter.GetBytes(m_CellOffset[i]);
  66. Array.Copy(tmp, 0, r, pos, 2);
  67. //BitConverter.GetBytes( m_CellOffset[i]).CopyTo( r,pos);
  68. }
  69. return r;
  70. }
  71. #endregion
  72. }
  73. }