Style.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. internal enum EnumBuiltInStles
  9. {
  10. bsNormal = 0x0,
  11. bsComma = 0x3,
  12. bsCurrency = 0x4,
  13. bsPercent = 0x5,
  14. bsCommaZero = 0x6,
  15. bsCurrencyZero = 0x7
  16. }
  17. internal enum EnumStyleType
  18. {
  19. sUserDefined = 0x0,
  20. sBuiltIn = 0x1
  21. }
  22. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
  23. struct RecordStyle
  24. {
  25. public ushort opcode;
  26. public ushort length;
  27. public ushort xfindex;
  28. public ushort nameLength;
  29. }
  30. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
  31. struct RecordStyle2
  32. {
  33. public ushort opcode;
  34. public ushort length;
  35. public ushort xfindex;
  36. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte builtinstyle;
  37. }
  38. internal class Style : IRecords
  39. {
  40. RecordStyle style;
  41. EnumStyleType stype;
  42. string m_name;
  43. byte m_builtinstyle;
  44. public Style()
  45. {
  46. style.opcode = 0x293;
  47. style.xfindex = 0x0;
  48. stype = EnumStyleType.sBuiltIn;
  49. }
  50. public ushort ID
  51. {
  52. get { return style.opcode; }
  53. }
  54. public ushort RecordSize
  55. {
  56. get { return 22; }
  57. }
  58. public EnumStyleType StyleType
  59. {
  60. set
  61. {
  62. stype = value;
  63. int i = (int)value;
  64. i <<= 15; //Set the last bit
  65. style.xfindex = (ushort)((ushort)style.xfindex | (ushort)i);
  66. }
  67. }
  68. public ushort XFIndex
  69. {
  70. set { style.xfindex |= value; }
  71. }
  72. public EnumBuiltInStles BuiltinStyle
  73. {
  74. set
  75. {
  76. m_builtinstyle = (byte)value;
  77. }
  78. }
  79. public string UserStyleName
  80. {
  81. set
  82. {
  83. style.nameLength = (ushort)Globals.GetDefaultBytesLength(value);
  84. m_name = value;
  85. }
  86. }
  87. #region IRecords ³ÉÔ±
  88. public byte[] GetByte()
  89. {
  90. byte[] b;
  91. int ln = (stype == EnumStyleType.sBuiltIn ? 8 : (Globals.GetDefaultBytesLength(m_name) + 8));
  92. b = new byte[ln];
  93. style.length = (ushort)(b.Length - 4);
  94. if (stype == EnumStyleType.sBuiltIn)
  95. {
  96. RecordStyle2 st;
  97. st.opcode = style.opcode;
  98. st.length = style.length;
  99. st.xfindex = style.xfindex;
  100. st.builtinstyle = m_builtinstyle;
  101. Globals.GetStructToBytes(st).CopyTo(b, 0);
  102. }
  103. else
  104. {
  105. Globals.GetStructToBytes(style).CopyTo(b, 0);
  106. Globals.GetDefaultBytes(m_name).CopyTo(b, 8);
  107. }
  108. return b;
  109. }
  110. #endregion
  111. }
  112. }