BoundSheet.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 RecordBoundSheet
  10. {
  11. public ushort opcode; // 0x85;
  12. public ushort length;
  13. public uint streamPosition;
  14. [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte visibility;
  15. [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte sheetType; // = 0x0;
  16. [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte namelength;
  17. [MarshalAs(UnmanagedType.U1, SizeConst = 1)] public byte zero; // Unicode flag (compressed String)
  18. }
  19. internal class BoundSheet : IRecords
  20. {
  21. RecordBoundSheet boundsheet;
  22. string sheetName;
  23. byte[] sheetNameBytes;
  24. ushort recLen;
  25. public BoundSheet()
  26. {
  27. boundsheet.opcode = 0x85;
  28. boundsheet.sheetType = 0x0;
  29. boundsheet.zero = 0x0;
  30. }
  31. internal ushort ID
  32. {
  33. get{ return boundsheet.opcode ;}
  34. }
  35. internal ushort RecordSize
  36. {
  37. get { return recLen; }
  38. }
  39. internal uint StreamPosition
  40. {
  41. set {boundsheet.streamPosition = value;}
  42. }
  43. internal string StreamName
  44. {
  45. set
  46. {
  47. sheetName = value;
  48. if (sheetName.Length != Globals.GetDefaultBytesLength(sheetName))
  49. {
  50. boundsheet.zero = 0x1;
  51. sheetNameBytes = Globals.GetUnicodeBytes(sheetName);
  52. }
  53. else
  54. {
  55. boundsheet.zero = 0x0;
  56. sheetNameBytes = Globals.GetDefaultBytes(sheetName);
  57. }
  58. }
  59. }
  60. internal byte Visible
  61. {
  62. set {boundsheet.visibility |= value;}
  63. }
  64. #region IRecords ³ÉÔ±
  65. public byte[] GetByte()
  66. {
  67. byte[] b;
  68. if (sheetName == null)
  69. throw new Biff8ExcelException("ÇëÏÈÉ趨sheetName");
  70. //recLen = (ushort)(sheetName.Length + 12);
  71. //recLen = (ushort)(Globals.GetUnicodeByteLength(sheetName) + 12);
  72. recLen = (ushort)(sheetNameBytes.Length + 12);
  73. b = new byte[recLen];
  74. boundsheet.length = (ushort)(b.Length - 4);
  75. //boundsheet.namelength = (byte)(Globals.GetByteLength(sheetName));
  76. boundsheet.namelength = (byte)sheetName.Length;
  77. Globals.GetStructToBytes(boundsheet).CopyTo(b, 0);
  78. //Globals.GetBytes(sheetName).CopyTo(b, 12);
  79. //Globals.GetUnicodeBytes(sheetName).CopyTo(b, 12);
  80. sheetNameBytes.CopyTo(b, 12);
  81. return b;
  82. }
  83. #endregion
  84. }
  85. }