newDGVtoExcel.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using System.Runtime.CompilerServices;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using Microsoft.VisualBasic;
  8. using Microsoft.VisualBasic.CompilerServices;
  9. namespace Dongke.IBOSS.PRD.Framework.Controls
  10. {
  11. [EditorBrowsable(EditorBrowsableState.Never)]
  12. public class newDGVtoExcel
  13. {
  14. public enum ValueTypes
  15. {
  16. xlsInteger,
  17. xlsNumber,
  18. xlsText
  19. }
  20. public enum CellAlignment
  21. {
  22. xlsGeneralAlign = 0,
  23. xlsLeftAlign = 1,
  24. xlsCentreAlign = 2,
  25. xlsRightAlign = 3,
  26. xlsFillCell = 4,
  27. xlsLeftBorder = 8,
  28. xlsRightBorder = 16,
  29. xlsTopBorder = 32,
  30. xlsBottomBorder = 64,
  31. xlsShaded = 128
  32. }
  33. public enum CellFont
  34. {
  35. xlsFont0 = 0,
  36. xlsFont1 = 64,
  37. xlsFont2 = 128,
  38. xlsFont3 = 192
  39. }
  40. public enum CellHiddenLocked
  41. {
  42. xlsNormal = 0,
  43. xlsLocked = 0x40,
  44. xlsHidden = 0x80
  45. }
  46. public enum MarginTypes
  47. {
  48. xlsLeftMargin = 38,
  49. xlsRightMargin,
  50. xlsTopMargin,
  51. xlsBottomMargin
  52. }
  53. public enum FontFormatting
  54. {
  55. xlsNoFormat = 0,
  56. xlsBold = 1,
  57. xlsItalic = 2,
  58. xlsUnderline = 4,
  59. xlsStrikeout = 8
  60. }
  61. private struct FONT_RECORD
  62. {
  63. public short opcode;
  64. public short length;
  65. public short FontHeight;
  66. public byte FontAttributes1;
  67. public byte FontAttributes2;
  68. public byte FontNameLength;
  69. }
  70. private struct PASSWORD_RECORD
  71. {
  72. public short opcode;
  73. public short length;
  74. }
  75. private struct HEADER_FOOTER_RECORD
  76. {
  77. public short opcode;
  78. public short length;
  79. public byte TextLength;
  80. }
  81. private struct PROTECT_SPREADSHEET_RECORD
  82. {
  83. public short opcode;
  84. public short length;
  85. public short Protect;
  86. }
  87. private struct FORMAT_COUNT_RECORD
  88. {
  89. public short opcode;
  90. public short length;
  91. public short Count;
  92. }
  93. private struct FORMAT_RECORD
  94. {
  95. public short opcode;
  96. public short length;
  97. public byte FormatLenght;
  98. }
  99. private struct COLWIDTH_RECORD
  100. {
  101. public short opcode;
  102. public short length;
  103. public byte col1;
  104. public byte col2;
  105. public short ColumnWidth;
  106. }
  107. private struct BEG_FILE_RECORD
  108. {
  109. public short opcode;
  110. public short length;
  111. public short version;
  112. public short ftype;
  113. }
  114. private struct END_FILE_RECORD
  115. {
  116. public short opcode;
  117. public short length;
  118. }
  119. private struct PRINT_GRIDLINES_RECORD
  120. {
  121. public short opcode;
  122. public short length;
  123. public short PrintFlag;
  124. }
  125. private struct tInteger
  126. {
  127. public short opcode;
  128. public short length;
  129. public short row;
  130. public short col;
  131. public byte rgbAttr1;
  132. public byte rgbAttr2;
  133. public byte rgbAttr3;
  134. public short intValue;
  135. }
  136. private struct tNumber
  137. {
  138. public short opcode;
  139. public short length;
  140. public short row;
  141. public short col;
  142. public byte rgbAttr1;
  143. public byte rgbAttr2;
  144. public byte rgbAttr3;
  145. public double NumberValue;
  146. }
  147. private struct tText
  148. {
  149. public short opcode;
  150. public short length;
  151. public short row;
  152. public short col;
  153. public byte rgbAttr1;
  154. public byte rgbAttr2;
  155. public byte rgbAttr3;
  156. public byte TextLength;
  157. }
  158. private struct MARGIN_RECORD_LAYOUT
  159. {
  160. public short opcode;
  161. public short length;
  162. public double MarginValue;
  163. }
  164. private struct HPAGE_BREAK_RECORD
  165. {
  166. public short opcode;
  167. public short length;
  168. public short NumPageBreaks;
  169. }
  170. private struct DEF_ROWHEIGHT_RECORD
  171. {
  172. public int opcode;
  173. public int length;
  174. public int RowHeight;
  175. }
  176. private struct ROW_HEIGHT_RECORD
  177. {
  178. public int opcode;
  179. public int length;
  180. public int RowNumber;
  181. public int FirstColumn;
  182. public int LastColumn;
  183. public int RowHeight;
  184. public int @internal;
  185. public byte DefaultAttributes;
  186. public int FileOffset;
  187. public byte rgbAttr1;
  188. public byte rgbAttr2;
  189. public byte rgbAttr3;
  190. }
  191. private int m_shtFileNumber;
  192. private BEG_FILE_RECORD m_udtBEG_FILE_MARKER;
  193. private END_FILE_RECORD m_udtEND_FILE_MARKER;
  194. private HPAGE_BREAK_RECORD m_udtHORIZ_PAGE_BREAK;
  195. private short[] m_shtHorizPageBreakRows;
  196. private short m_shtNumHorizPageBreaks;
  197. public bool PrintGridLines
  198. {
  199. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  200. set
  201. {
  202. try
  203. {
  204. PRINT_GRIDLINES_RECORD pRINT_GRIDLINES_RECORD = default(PRINT_GRIDLINES_RECORD);
  205. pRINT_GRIDLINES_RECORD.opcode = 43;
  206. pRINT_GRIDLINES_RECORD.length = 2;
  207. if (value)
  208. {
  209. pRINT_GRIDLINES_RECORD.PrintFlag = 1;
  210. }
  211. else
  212. {
  213. pRINT_GRIDLINES_RECORD.PrintFlag = 0;
  214. }
  215. FileSystem.FilePut(m_shtFileNumber, pRINT_GRIDLINES_RECORD, -1L);
  216. }
  217. catch (Exception projectError)
  218. {
  219. ProjectData.SetProjectError(projectError);
  220. ProjectData.ClearProjectError();
  221. }
  222. }
  223. }
  224. public bool ProtectSpreadsheet
  225. {
  226. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  227. set
  228. {
  229. try
  230. {
  231. PROTECT_SPREADSHEET_RECORD pROTECT_SPREADSHEET_RECORD = default(PROTECT_SPREADSHEET_RECORD);
  232. pROTECT_SPREADSHEET_RECORD.opcode = 18;
  233. pROTECT_SPREADSHEET_RECORD.length = 2;
  234. if (value)
  235. {
  236. pROTECT_SPREADSHEET_RECORD.Protect = 1;
  237. }
  238. else
  239. {
  240. pROTECT_SPREADSHEET_RECORD.Protect = 0;
  241. }
  242. FileSystem.FilePut(m_shtFileNumber, pROTECT_SPREADSHEET_RECORD, -1L);
  243. }
  244. catch (Exception projectError)
  245. {
  246. ProjectData.SetProjectError(projectError);
  247. ProjectData.ClearProjectError();
  248. }
  249. }
  250. }
  251. [DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "RtlMoveMemory", ExactSpelling = true, SetLastError = true)]
  252. private static extern void CopyMemory([MarshalAs(UnmanagedType.AnsiBStr)] ref string lpvDest, ref short lpvSource, int cbCopy);
  253. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  254. public int CreateFile(string strFileName)
  255. {
  256. int result;
  257. try
  258. {
  259. if (File.Exists(strFileName))
  260. {
  261. File.SetAttributes(strFileName, FileAttributes.Normal);
  262. File.Delete(strFileName);
  263. }
  264. m_shtFileNumber = FileSystem.FreeFile();
  265. FileSystem.FileOpen(m_shtFileNumber, strFileName, OpenMode.Binary);
  266. FileSystem.FilePut(m_shtFileNumber, m_udtBEG_FILE_MARKER, -1L);
  267. WriteDefaultFormats();
  268. m_shtHorizPageBreakRows = new short[1];
  269. m_shtNumHorizPageBreaks = 0;
  270. result = 0;
  271. }
  272. catch (Exception projectError)
  273. {
  274. ProjectData.SetProjectError(projectError);
  275. result = Information.Err().Number;
  276. ProjectData.ClearProjectError();
  277. }
  278. return result;
  279. }
  280. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  281. public int CloseFile()
  282. {
  283. int result;
  284. try
  285. {
  286. if (m_shtFileNumber > 0)
  287. {
  288. if (m_shtNumHorizPageBreaks > 0)
  289. {
  290. int num = Information.UBound(m_shtHorizPageBreakRows);
  291. int num2 = Information.LBound(m_shtHorizPageBreakRows);
  292. short num6;
  293. short num7;
  294. checked
  295. {
  296. for (int i = num; i >= num2; i += -1)
  297. {
  298. int num3 = Information.LBound(m_shtHorizPageBreakRows) + 1;
  299. int num4 = i;
  300. for (int j = num3; j <= num4; j++)
  301. {
  302. if (m_shtHorizPageBreakRows[j - 1] > m_shtHorizPageBreakRows[j])
  303. {
  304. int num5 = m_shtHorizPageBreakRows[j - 1];
  305. m_shtHorizPageBreakRows[j - 1] = m_shtHorizPageBreakRows[j];
  306. m_shtHorizPageBreakRows[j] = (short)num5;
  307. }
  308. }
  309. }
  310. m_udtHORIZ_PAGE_BREAK.opcode = 27;
  311. m_udtHORIZ_PAGE_BREAK.length = Convert.ToSByte(2 + m_shtNumHorizPageBreaks * 2);
  312. m_udtHORIZ_PAGE_BREAK.NumPageBreaks = m_shtNumHorizPageBreaks;
  313. FileSystem.FilePut(m_shtFileNumber, m_udtHORIZ_PAGE_BREAK, -1L);
  314. num6 = 1;
  315. num7 = (short)Information.UBound(m_shtHorizPageBreakRows);
  316. }
  317. for (short num8 = num6; num8 <= num7; num8++)
  318. {
  319. FileSystem.FilePut(m_shtFileNumber, MKI(ref m_shtHorizPageBreakRows[num8]), -1L);
  320. }
  321. }
  322. FileSystem.FilePut(m_shtFileNumber, m_udtEND_FILE_MARKER, -1L);
  323. FileSystem.FileClose(m_shtFileNumber);
  324. result = 0;
  325. }
  326. else
  327. {
  328. result = -1;
  329. }
  330. }
  331. catch (Exception projectError)
  332. {
  333. ProjectData.SetProjectError(projectError);
  334. result = Information.Err().Number;
  335. ProjectData.ClearProjectError();
  336. }
  337. return result;
  338. }
  339. private void Init()
  340. {
  341. m_udtBEG_FILE_MARKER.opcode = 9;
  342. m_udtBEG_FILE_MARKER.length = 4;
  343. m_udtBEG_FILE_MARKER.version = 2;
  344. m_udtBEG_FILE_MARKER.ftype = 10;
  345. m_udtEND_FILE_MARKER.opcode = 10;
  346. }
  347. public newDGVtoExcel()
  348. {
  349. Init();
  350. }
  351. public int InsertHorizPageBreak(ref int lrow)
  352. {
  353. checked
  354. {
  355. int result;
  356. try
  357. {
  358. short num = ((lrow <= 32767) ? ((short)(lrow - 1)) : ((short)(lrow - 65536)));
  359. m_shtNumHorizPageBreaks++;
  360. m_shtHorizPageBreakRows = (short[])Utils.CopyArray(m_shtHorizPageBreakRows, new short[m_shtNumHorizPageBreaks + 1]);
  361. m_shtHorizPageBreakRows[m_shtNumHorizPageBreaks] = num;
  362. result = 0;
  363. }
  364. catch (Exception projectError)
  365. {
  366. ProjectData.SetProjectError(projectError);
  367. result = Information.Err().Number;
  368. ProjectData.ClearProjectError();
  369. }
  370. return result;
  371. }
  372. }
  373. public int WriteValue(ref ValueTypes ValueType, ref int lrow, ref int lcol, object Value)
  374. {
  375. CellFont CellFontUsed = CellFont.xlsFont0;
  376. CellAlignment Alignment = (CellAlignment)120;
  377. CellHiddenLocked HiddenLocked = CellHiddenLocked.xlsNormal;
  378. object objectValue = RuntimeHelpers.GetObjectValue(Value);
  379. int CellFormat = 0;
  380. return WriteValue(ref ValueType, ref CellFontUsed, ref Alignment, ref HiddenLocked, ref lrow, ref lcol, objectValue, ref CellFormat);
  381. }
  382. public int WriteValue(ref ValueTypes ValueType, ref CellAlignment Alignment, ref int lrow, ref int lcol, object Value)
  383. {
  384. CellFont CellFontUsed = CellFont.xlsFont0;
  385. CellHiddenLocked HiddenLocked = CellHiddenLocked.xlsNormal;
  386. object objectValue = RuntimeHelpers.GetObjectValue(Value);
  387. int CellFormat = 0;
  388. return WriteValue(ref ValueType, ref CellFontUsed, ref Alignment, ref HiddenLocked, ref lrow, ref lcol, objectValue, ref CellFormat);
  389. }
  390. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  391. public int WriteValue(ref ValueTypes ValueType, ref CellFont CellFontUsed, ref CellAlignment Alignment, ref CellHiddenLocked HiddenLocked, ref int lrow, ref int lcol, object Value, ref int CellFormat)
  392. {
  393. checked
  394. {
  395. int result;
  396. try
  397. {
  398. //short row = ((lrow <= 32768) ? ((short)(lrow - 1)) : ((short)(lrow - 65536 - 1)));
  399. //short col = ((lcol <= 32768) ? ((short)(lcol - 1)) : ((short)(lcol - 65536 - 1)));
  400. short row = (short)(lrow - 1);
  401. short col = (short)(lcol - 1);
  402. switch (ValueType)
  403. {
  404. case ValueTypes.xlsInteger:
  405. {
  406. tInteger tInteger = default(tInteger);
  407. tInteger.opcode = 2;
  408. tInteger.length = 9;
  409. tInteger.row = row;
  410. tInteger.col = col;
  411. tInteger.rgbAttr1 = (byte)HiddenLocked;
  412. tInteger.rgbAttr2 = (byte)(CellFontUsed + CellFormat);
  413. tInteger.rgbAttr3 = (byte)Alignment;
  414. tInteger.intValue = Conversions.ToShort(Value);
  415. FileSystem.FilePut(m_shtFileNumber, tInteger, -1L);
  416. break;
  417. }
  418. case ValueTypes.xlsNumber:
  419. {
  420. tNumber tNumber = default(tNumber);
  421. tNumber.opcode = 3;
  422. tNumber.length = 15;
  423. tNumber.row = row;
  424. tNumber.col = col;
  425. tNumber.rgbAttr1 = (byte)HiddenLocked;
  426. tNumber.rgbAttr2 = (byte)(CellFontUsed + CellFormat);
  427. tNumber.rgbAttr3 = (byte)Alignment;
  428. tNumber.NumberValue = Conversions.ToDouble(Value);
  429. FileSystem.FilePut(m_shtFileNumber, tNumber, -1L);
  430. break;
  431. }
  432. case ValueTypes.xlsText:
  433. {
  434. string text = Conversions.ToString(Value);
  435. short num = (short)GetLength(text);
  436. tText tText = default(tText);
  437. tText.opcode = 4;
  438. tText.length = 10;
  439. tText.TextLength = (byte)num;
  440. tText.length = Convert.ToSByte(8 + num);
  441. tText.row = row;
  442. tText.col = col;
  443. tText.rgbAttr1 = (byte)HiddenLocked;
  444. tText.rgbAttr2 = (byte)(CellFontUsed + CellFormat);
  445. tText.rgbAttr3 = (byte)Alignment;
  446. FileSystem.FilePut(m_shtFileNumber, tText, -1L);
  447. FileSystem.FilePut(m_shtFileNumber, text, -1L);
  448. break;
  449. }
  450. }
  451. result = 0;
  452. }
  453. catch (Exception projectError)
  454. {
  455. ProjectData.SetProjectError(projectError);
  456. result = Information.Err().Number;
  457. ProjectData.ClearProjectError();
  458. }
  459. return result;
  460. }
  461. }
  462. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  463. public int SetMargin(ref MarginTypes Margin, ref double MarginValue)
  464. {
  465. int result;
  466. try
  467. {
  468. MARGIN_RECORD_LAYOUT mARGIN_RECORD_LAYOUT = default(MARGIN_RECORD_LAYOUT);
  469. mARGIN_RECORD_LAYOUT.opcode = checked((short)Margin);
  470. mARGIN_RECORD_LAYOUT.length = 8;
  471. mARGIN_RECORD_LAYOUT.MarginValue = MarginValue;
  472. FileSystem.FilePut(m_shtFileNumber, mARGIN_RECORD_LAYOUT, -1L);
  473. result = 0;
  474. }
  475. catch (Exception projectError)
  476. {
  477. ProjectData.SetProjectError(projectError);
  478. result = Information.Err().Number;
  479. ProjectData.ClearProjectError();
  480. }
  481. return result;
  482. }
  483. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  484. public int SetColumnWidth(ref byte FirstColumn, ref byte LastColumn, ref short WidthValue)
  485. {
  486. checked
  487. {
  488. int result;
  489. try
  490. {
  491. COLWIDTH_RECORD cOLWIDTH_RECORD = default(COLWIDTH_RECORD);
  492. cOLWIDTH_RECORD.opcode = 36;
  493. cOLWIDTH_RECORD.length = 4;
  494. cOLWIDTH_RECORD.col1 = Convert.ToByte(FirstColumn - 1);
  495. cOLWIDTH_RECORD.col2 = Convert.ToByte(LastColumn - 1);
  496. cOLWIDTH_RECORD.ColumnWidth = Convert.ToSByte(WidthValue * 256);
  497. FileSystem.FilePut(m_shtFileNumber, cOLWIDTH_RECORD, -1L);
  498. result = 0;
  499. }
  500. catch (Exception projectError)
  501. {
  502. ProjectData.SetProjectError(projectError);
  503. result = Information.Err().Number;
  504. ProjectData.ClearProjectError();
  505. }
  506. return result;
  507. }
  508. }
  509. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  510. public short SetFont(ref string FontName, ref short FontHeight, ref FontFormatting FontFormat)
  511. {
  512. checked
  513. {
  514. short result;
  515. try
  516. {
  517. short num = (short)GetLength(FontName);
  518. FONT_RECORD fONT_RECORD = default(FONT_RECORD);
  519. fONT_RECORD.opcode = 49;
  520. fONT_RECORD.length = Convert.ToSByte(5 + num);
  521. fONT_RECORD.FontHeight = Convert.ToSByte(FontHeight * 20);
  522. fONT_RECORD.FontAttributes1 = (byte)FontFormat;
  523. fONT_RECORD.FontAttributes2 = 0;
  524. fONT_RECORD.FontNameLength = (byte)num;
  525. FileSystem.FilePut(m_shtFileNumber, fONT_RECORD, -1L);
  526. FileSystem.FilePut(m_shtFileNumber, FontName, -1L);
  527. result = 0;
  528. }
  529. catch (Exception projectError)
  530. {
  531. ProjectData.SetProjectError(projectError);
  532. result = (short)Information.Err().Number;
  533. ProjectData.ClearProjectError();
  534. }
  535. return result;
  536. }
  537. }
  538. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  539. public int SetHeader(ref string HeaderText)
  540. {
  541. checked
  542. {
  543. int result;
  544. try
  545. {
  546. short num = (short)GetLength(HeaderText);
  547. HEADER_FOOTER_RECORD hEADER_FOOTER_RECORD = default(HEADER_FOOTER_RECORD);
  548. hEADER_FOOTER_RECORD.opcode = 20;
  549. hEADER_FOOTER_RECORD.length = Convert.ToSByte(1 + num);
  550. hEADER_FOOTER_RECORD.TextLength = (byte)num;
  551. FileSystem.FilePut(m_shtFileNumber, hEADER_FOOTER_RECORD, -1L);
  552. FileSystem.FilePut(m_shtFileNumber, HeaderText, -1L);
  553. result = 0;
  554. }
  555. catch (Exception projectError)
  556. {
  557. ProjectData.SetProjectError(projectError);
  558. result = Information.Err().Number;
  559. ProjectData.ClearProjectError();
  560. }
  561. return result;
  562. }
  563. }
  564. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  565. public int SetFooter(ref string FooterText)
  566. {
  567. checked
  568. {
  569. int result;
  570. try
  571. {
  572. short num = (short)GetLength(FooterText);
  573. HEADER_FOOTER_RECORD hEADER_FOOTER_RECORD = default(HEADER_FOOTER_RECORD);
  574. hEADER_FOOTER_RECORD.opcode = 21;
  575. hEADER_FOOTER_RECORD.length = Convert.ToSByte(1 + num);
  576. hEADER_FOOTER_RECORD.TextLength = (byte)num;
  577. FileSystem.FilePut(m_shtFileNumber, hEADER_FOOTER_RECORD, -1L);
  578. FileSystem.FilePut(m_shtFileNumber, FooterText, -1L);
  579. result = 0;
  580. }
  581. catch (Exception projectError)
  582. {
  583. ProjectData.SetProjectError(projectError);
  584. result = Information.Err().Number;
  585. ProjectData.ClearProjectError();
  586. }
  587. return result;
  588. }
  589. }
  590. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  591. public int SetFilePassword(ref string PasswordText)
  592. {
  593. int result;
  594. try
  595. {
  596. short length = checked((short)GetLength(PasswordText));
  597. PASSWORD_RECORD pASSWORD_RECORD = default(PASSWORD_RECORD);
  598. pASSWORD_RECORD.opcode = 47;
  599. pASSWORD_RECORD.length = length;
  600. FileSystem.FilePut(m_shtFileNumber, pASSWORD_RECORD, -1L);
  601. FileSystem.FilePut(m_shtFileNumber, PasswordText, -1L);
  602. result = 0;
  603. }
  604. catch (Exception projectError)
  605. {
  606. ProjectData.SetProjectError(projectError);
  607. result = Information.Err().Number;
  608. ProjectData.ClearProjectError();
  609. }
  610. return result;
  611. }
  612. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  613. private void WriteDefaultFormats()
  614. {
  615. string[] array = new string[24];
  616. string text = "\"";
  617. array[0] = "General";
  618. array[1] = "0";
  619. array[2] = "0.00";
  620. array[3] = "#,##0";
  621. array[4] = "#,##0.00";
  622. array[5] = "#,##0/ " + text + "$" + text + ";/-#,##0/ " + text + "$" + text;
  623. array[6] = "#,##0/ " + text + "$" + text + ";[Red]/-#,##0/ " + text + "$" + text;
  624. array[7] = "#,##0.00/ " + text + "$" + text + ";/-#,##0.00/ " + text + "$" + text;
  625. array[8] = "#,##0.00/ " + text + "$" + text + ";[Red]/-#,##0.00/ " + text + "$" + text;
  626. array[9] = "0%";
  627. array[10] = "0.00%";
  628. array[11] = "0.00E+00";
  629. array[12] = "dd/mm/yy";
  630. array[13] = "dd// mmm/ yy";
  631. array[14] = "dd// mmm";
  632. array[15] = "mmm/ yy";
  633. array[16] = "h:mm/ AM/PM";
  634. array[17] = "h:mm:ss/ AM/PM";
  635. array[18] = "hh:mm";
  636. array[19] = "hh:mm:ss";
  637. array[20] = "dd/mm/yy/ hh:mm";
  638. array[21] = "##0.0E+0";
  639. array[22] = "mm:ss";
  640. array[23] = "@";
  641. FORMAT_COUNT_RECORD fORMAT_COUNT_RECORD = default(FORMAT_COUNT_RECORD);
  642. fORMAT_COUNT_RECORD.opcode = 31;
  643. fORMAT_COUNT_RECORD.length = 2;
  644. checked
  645. {
  646. fORMAT_COUNT_RECORD.Count = (short)Information.UBound(array);
  647. FileSystem.FilePut(m_shtFileNumber, fORMAT_COUNT_RECORD, -1L);
  648. int num = Information.LBound(array);
  649. int num2 = Information.UBound(array);
  650. FORMAT_RECORD fORMAT_RECORD = default(FORMAT_RECORD);
  651. for (int i = num; i <= num2; i++)
  652. {
  653. int num3 = Strings.Len(array[i]);
  654. fORMAT_RECORD.opcode = 30;
  655. fORMAT_RECORD.length = (short)(num3 + 1);
  656. fORMAT_RECORD.FormatLenght = (byte)num3;
  657. FileSystem.FilePut(m_shtFileNumber, fORMAT_RECORD, -1L);
  658. int num4 = 1;
  659. int num5 = num3;
  660. for (int j = num4; j <= num5; j++)
  661. {
  662. byte value = (byte)Strings.Asc(Strings.Mid(array[i], j, 1));
  663. FileSystem.FilePut(m_shtFileNumber, value, -1L);
  664. }
  665. }
  666. }
  667. }
  668. private static string MKI(ref short x)
  669. {
  670. string lpvDest = Strings.Space(2);
  671. CopyMemory(ref lpvDest, ref x, 2);
  672. return lpvDest;
  673. }
  674. private static int GetLength(string strText)
  675. {
  676. return Encoding.Default.GetBytes(strText).Length;
  677. }
  678. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  679. public int SetDefaultRowHeight(int HeightValue)
  680. {
  681. int result;
  682. try
  683. {
  684. DEF_ROWHEIGHT_RECORD dEF_ROWHEIGHT_RECORD = default(DEF_ROWHEIGHT_RECORD);
  685. dEF_ROWHEIGHT_RECORD.opcode = 37;
  686. dEF_ROWHEIGHT_RECORD.length = 2;
  687. dEF_ROWHEIGHT_RECORD.RowHeight = checked(HeightValue * 20);
  688. FileSystem.FilePut(m_shtFileNumber, dEF_ROWHEIGHT_RECORD, -1L);
  689. result = 0;
  690. }
  691. catch (Exception projectError)
  692. {
  693. ProjectData.SetProjectError(projectError);
  694. result = Information.Err().Number;
  695. ProjectData.ClearProjectError();
  696. }
  697. return result;
  698. }
  699. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
  700. public int SetRowHeight(int Row, short HeightValue)
  701. {
  702. checked
  703. {
  704. int result;
  705. try
  706. {
  707. int rowNumber = ((Row <= 32767) ? (Row - 1) : (Row - 65536));
  708. ROW_HEIGHT_RECORD rOW_HEIGHT_RECORD = default(ROW_HEIGHT_RECORD);
  709. rOW_HEIGHT_RECORD.opcode = 8;
  710. rOW_HEIGHT_RECORD.length = 16;
  711. rOW_HEIGHT_RECORD.RowNumber = rowNumber;
  712. rOW_HEIGHT_RECORD.FirstColumn = 0;
  713. rOW_HEIGHT_RECORD.LastColumn = 256;
  714. rOW_HEIGHT_RECORD.RowHeight = HeightValue * 20;
  715. rOW_HEIGHT_RECORD.@internal = 0;
  716. rOW_HEIGHT_RECORD.DefaultAttributes = 0;
  717. rOW_HEIGHT_RECORD.FileOffset = 0;
  718. rOW_HEIGHT_RECORD.rgbAttr1 = 0;
  719. rOW_HEIGHT_RECORD.rgbAttr2 = 0;
  720. rOW_HEIGHT_RECORD.rgbAttr3 = 0;
  721. FileSystem.FilePut(m_shtFileNumber, rOW_HEIGHT_RECORD, -1L);
  722. result = 0;
  723. }
  724. catch (Exception projectError)
  725. {
  726. ProjectData.SetProjectError(projectError);
  727. result = Information.Err().Number;
  728. ProjectData.ClearProjectError();
  729. }
  730. return result;
  731. }
  732. }
  733. }
  734. }