ExtendedFormat.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 RecordExtendedFormat
  10. {
  11. public ushort opcode;
  12. public ushort length;
  13. public ushort fontIndex;
  14. public ushort formatIndex;
  15. public ushort cellOptions;
  16. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte alignmentOptions;
  17. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte rotationOptions;
  18. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte indentationOpions;
  19. [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte usedAttribute;
  20. public uint borderOptions1;
  21. public uint borderOptions2;
  22. public ushort fillPalleteOptions;
  23. }
  24. internal class ExtendedFormat : IRecords
  25. {
  26. byte mHAlign;
  27. byte mWrapText;
  28. byte mVAlign;
  29. uint mLeftLineStyle;
  30. uint mRightLineStyle;
  31. uint mTopLineStyle;
  32. uint mBottomLineStyle;
  33. uint mLeftColourIndex;
  34. uint mRightColourIndex;
  35. uint mDiagTLBR;
  36. uint mDiagTRBL;
  37. uint mTopColourIndex;
  38. uint mBottomColourIndex;
  39. uint mDiagColourIndex;
  40. uint mDiagLineStyle;
  41. uint mFillPattern;
  42. ushort mPatternFore ;
  43. ushort mPatternBack;
  44. RecordExtendedFormat extendedformat;
  45. public ExtendedFormat()
  46. {
  47. extendedformat.opcode = 0xE0;
  48. extendedformat.length = 0x14;
  49. }
  50. public ushort ID
  51. {
  52. get { return extendedformat.opcode; }
  53. }
  54. public ushort RecordSize
  55. {
  56. get { return 24; }
  57. }
  58. public ushort FontIndex
  59. {
  60. set { extendedformat.fontIndex = value; }
  61. }
  62. public ushort FormatIndex
  63. {
  64. set
  65. {
  66. extendedformat.formatIndex = value;
  67. }
  68. }
  69. public bool CellIsLocked
  70. {
  71. set
  72. {
  73. if (value)
  74. extendedformat.cellOptions |= 0x1;
  75. else
  76. //extendedformat.cellOptions &= ~0x1;
  77. extendedformat.cellOptions = (ushort)(extendedformat.cellOptions & (~0x1));
  78. }
  79. }
  80. public bool FormulaHidden
  81. {
  82. set {
  83. if (value)
  84. extendedformat.cellOptions |= 0x2;
  85. else
  86. //extendedformat.cellOptions &= ~0x2;
  87. extendedformat.cellOptions = (ushort)(extendedformat.cellOptions & (~0x2));
  88. }
  89. }
  90. public byte StyleType
  91. {
  92. set
  93. {
  94. if (value == 0x1) //SheetStyle
  95. {
  96. extendedformat.cellOptions |= 0x4;
  97. extendedformat.cellOptions = (ushort)(extendedformat.cellOptions | 0xFFF0);
  98. //extendedformat.cellOptions |= -16;
  99. }
  100. else
  101. {
  102. //extendedformat.cellOptions &= ~0x4;
  103. extendedformat.cellOptions = (ushort)(extendedformat.cellOptions & (~0x4));
  104. }
  105. }
  106. }
  107. void SetAlignment()
  108. {
  109. extendedformat.alignmentOptions = 0;
  110. extendedformat.alignmentOptions |= mHAlign;
  111. extendedformat.alignmentOptions |= mWrapText;
  112. extendedformat.alignmentOptions |= mVAlign;
  113. }
  114. public byte HorizontalAlignment
  115. {
  116. set
  117. {
  118. mHAlign = value;
  119. this.SetAlignment();
  120. }
  121. }
  122. public bool WrapText
  123. {
  124. set
  125. {
  126. mWrapText = (byte)(value ? 0x8 : 0x0);
  127. this.SetAlignment();
  128. }
  129. }
  130. public byte VerticalAlignment
  131. {
  132. set
  133. {
  134. mVAlign = value;
  135. //mVAlign = mVAlign * Math.Pow(2,4)
  136. mVAlign *= 16;
  137. this.SetAlignment();
  138. }
  139. }
  140. public byte TextRoationAngle
  141. {
  142. set { extendedformat.rotationOptions = value; }
  143. }
  144. public bool StackText
  145. {
  146. set
  147. {
  148. if (value)
  149. extendedformat.rotationOptions = 0xFF;
  150. }
  151. }
  152. public byte UsedAttribute
  153. {
  154. set { extendedformat.usedAttribute = value; }
  155. }
  156. void SetBorderOptions1()
  157. {
  158. extendedformat.borderOptions1 = 0;
  159. extendedformat.borderOptions1 |= mLeftLineStyle;
  160. extendedformat.borderOptions1 |= mRightLineStyle;
  161. extendedformat.borderOptions1 |= mTopLineStyle;
  162. extendedformat.borderOptions1 |= mBottomLineStyle;
  163. extendedformat.borderOptions1 |= mLeftColourIndex;
  164. extendedformat.borderOptions1 |= mRightColourIndex;
  165. extendedformat.borderOptions1 |= mDiagTLBR;
  166. extendedformat.borderOptions1 |= mDiagTRBL;
  167. }
  168. public byte LeftLineStyle
  169. {
  170. set
  171. {
  172. mLeftLineStyle = value;
  173. extendedformat.usedAttribute |= (0x8 << 2 );
  174. this.SetBorderOptions1();
  175. }
  176. }
  177. public byte LeftLineColour
  178. {
  179. set
  180. {
  181. // mLeftColourIndex = CLng(vData) * (2 ^ 16)
  182. mLeftColourIndex = (uint)(value << 16);
  183. this.SetBorderOptions1();
  184. }
  185. }
  186. public byte RightLineStyle
  187. {
  188. set
  189. {
  190. // mRightLineStyle = CLng(vData) * (2 ^ 4)
  191. mRightLineStyle = (uint)(value << 4);
  192. extendedformat.usedAttribute |= (0x8 << 2);
  193. this.SetBorderOptions1();
  194. }
  195. }
  196. public byte RightLineColour
  197. {
  198. set
  199. {
  200. // mRightColourIndex = CLng(vData) * (2 ^ 23)
  201. mRightColourIndex = (uint)(value << 23);
  202. this.SetBorderOptions1();
  203. }
  204. }
  205. public byte TopLineStyle
  206. {
  207. set
  208. {
  209. // mTopLineStyle = CLng(vData) * (2 ^ 8)
  210. mTopLineStyle = (uint)(value << 8);
  211. // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2))
  212. extendedformat.usedAttribute |= (0x8 << 2);
  213. this.SetBorderOptions1();
  214. }
  215. }
  216. public byte TopLineColour
  217. {
  218. set
  219. {
  220. // mTopColourIndex = CLng(vData) * (2 ^ 0)
  221. mTopColourIndex = value;
  222. this.SetBorderOptions2();
  223. }
  224. }
  225. public byte BottomLineStyle
  226. {
  227. set
  228. {
  229. // mBottomLineStyle = CLng(vData) * (2 ^ 12)
  230. mBottomLineStyle = (uint)(value << 12);
  231. // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2))
  232. extendedformat.usedAttribute |= (0x8 << 2);
  233. this.SetBorderOptions1();
  234. }
  235. }
  236. void SetBorderOptions2()
  237. {
  238. extendedformat.borderOptions2 = 0;
  239. extendedformat.borderOptions2 |= mTopColourIndex;
  240. extendedformat.borderOptions2 |= mBottomColourIndex;
  241. extendedformat.borderOptions2 |= mDiagColourIndex;
  242. extendedformat.borderOptions2 |= mDiagLineStyle;
  243. extendedformat.borderOptions2 |= mFillPattern;
  244. }
  245. public byte BottomLineColour
  246. {
  247. set
  248. {
  249. // mBottomColourIndex = CLng(vData) * (2 ^ 7)
  250. mBottomColourIndex = (uint)(value << 7);
  251. this.SetBorderOptions2();
  252. }
  253. }
  254. public byte DiagLineTopLeftToBottonRight
  255. {
  256. set
  257. {
  258. // mDiagTLBR = CLng(vData) * (2 ^ 30)
  259. mDiagTLBR = (uint)(value << 30);
  260. // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2))
  261. extendedformat.usedAttribute |= (0x8 << 2);
  262. this.SetBorderOptions1();
  263. }
  264. }
  265. public byte DiagLineTopRightToBottonLeft
  266. {
  267. set
  268. {
  269. mDiagTRBL = (uint)(value << 31);
  270. // field_6_used_Attribute = field_6_used_Attribute Or (&H8 * (2 ^ 2))
  271. extendedformat.usedAttribute |= (0x8 << 2);
  272. this.SetBorderOptions1();
  273. }
  274. }
  275. public byte DiagLineStyle
  276. {
  277. set
  278. {
  279. mDiagLineStyle = (uint)(value << 21);
  280. extendedformat.usedAttribute |= (0x8 << 2);
  281. this.SetBorderOptions2();
  282. }
  283. }
  284. public byte DiagLineColour
  285. {
  286. set
  287. {
  288. mDiagColourIndex = (uint)(value << 14);
  289. this.SetBorderOptions2();
  290. }
  291. }
  292. public byte FillPattern
  293. {
  294. set
  295. {
  296. mFillPattern = (uint)(value << 26);
  297. this.SetBorderOptions2();
  298. }
  299. }
  300. public byte PatternForeColour
  301. {
  302. set
  303. {
  304. mPatternFore = (ushort)(value << 0); //Shift Bits Up by 0
  305. extendedformat.fillPalleteOptions = 0;
  306. extendedformat.fillPalleteOptions |= mPatternFore;
  307. extendedformat.fillPalleteOptions |= mPatternBack;
  308. }
  309. }
  310. public byte PatternBackColour
  311. {
  312. set
  313. {
  314. mPatternBack = (ushort)(value << 7); //Shift Bits Up by 7
  315. extendedformat.fillPalleteOptions = 0;
  316. extendedformat.fillPalleteOptions |= mPatternFore;
  317. extendedformat.fillPalleteOptions |= mPatternBack;
  318. }
  319. }
  320. #region IRecords ³ÉÔ±
  321. public byte[] GetByte()
  322. {
  323. return Globals.GetStructToBytes(extendedformat);
  324. }
  325. #endregion
  326. }
  327. }