ExternSheet.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Biff8Excel.Excel
  5. {
  6. public class ExternSheet : Interfaces.IExternSheet, IDisposable
  7. {
  8. Biff8Excel.Records.ExternSheet m_extern;
  9. ushort numRefs;
  10. Records.StructExternSheet[] marrRefs;
  11. ExcelWorkbook mWorkbook;
  12. internal byte[] WriteRecord()
  13. {
  14. m_extern.ExternSheets = marrRefs;
  15. return m_extern.GetByte();
  16. }
  17. public ExcelWorkbook Workbook
  18. {
  19. set { mWorkbook = value; }
  20. }
  21. public ExternSheet()
  22. {
  23. m_extern = new Biff8Excel.Records.ExternSheet();
  24. }
  25. #region IDisposable ³ÉÔ±
  26. public void Dispose()
  27. {
  28. marrRefs = null;
  29. m_extern = null;
  30. mWorkbook = null;
  31. }
  32. #endregion
  33. #region IExternSheet ³ÉÔ±
  34. public void SheetNameToIndex(string sSheetName, ref ushort iSheetIndex)
  35. {
  36. iSheetIndex = mWorkbook.SheetIndexFromName(sSheetName);
  37. }
  38. public ushort AddEntry(string fromSheet)
  39. {
  40. return AddEntry(fromSheet, "");
  41. }
  42. public ushort AddEntry(string fromSheet, string toSheet)
  43. {
  44. ushort iFrom;
  45. ushort iTo;
  46. iFrom = mWorkbook.SheetIndexFromName(fromSheet);
  47. if (toSheet.Length == 0)
  48. {
  49. toSheet = fromSheet;
  50. iTo = iFrom;
  51. }
  52. else
  53. {
  54. iTo = mWorkbook.SheetIndexFromName(toSheet);
  55. }
  56. if (numRefs == 0)
  57. //marrRefs = TArray<Records.tExternSheet>.Preserve(marrRefs, 1);
  58. Array.Resize<Records.StructExternSheet>(ref marrRefs, 1);
  59. else
  60. //marrRefs = TArray<Records.tExternSheet>.Preserve(marrRefs, numRefs);
  61. Array.Resize<Records.StructExternSheet>(ref marrRefs, numRefs);
  62. // see if it already exists in the array
  63. for (ushort i = 0; i < numRefs; i++)
  64. {
  65. if (marrRefs[i].tFirstSheet == iFrom && marrRefs[i].tLastSheet == iTo)
  66. return i;
  67. }
  68. // add a new entry
  69. marrRefs[numRefs].tIndex = 0;
  70. marrRefs[numRefs].tFirstSheet = iFrom;
  71. marrRefs[numRefs].tLastSheet = iTo;
  72. numRefs++;
  73. return (ushort)(numRefs-1);
  74. }
  75. #endregion
  76. }
  77. }