Helper.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Biff8Excel.Excel
  5. {
  6. public class Helper:IDisposable
  7. {
  8. WorkSheetCollection m_workSheets; //reference to the worksheets collection
  9. public string ConvertColRowToRef(ushort columnNumer, ushort rowNumber)
  10. {
  11. return ConvertColRowToRef(columnNumer, rowNumber, -1);
  12. }
  13. public string ConvertColRowToRef(ushort columnNumer, ushort rowNumber, int sheet)
  14. {
  15. // Columns are zero based ,sheet 1 based
  16. string s = "";
  17. //ExcelWorksheet ws;
  18. if (sheet != -1)
  19. {
  20. if (sheet == 0)
  21. sheet = 1;
  22. s = m_workSheets[sheet].SheetName + "!";
  23. }
  24. return s + Globals.ConvertColNumToString(columnNumer) + rowNumber.ToString();
  25. }
  26. public string ConverColRowToAreaRef(ushort columnFrom, ushort rowFrom, ushort columnTo, ushort rowTo)
  27. {
  28. return ConverColRowToAreaRef(columnFrom, rowFrom, columnTo, rowTo,null,null);
  29. }
  30. public string ConverColRowToAreaRef(ushort columnFrom, ushort rowFrom, ushort columnTo, ushort rowTo, string sheetFrom, string sheetTo)
  31. {
  32. // Row and Columns are zero based, sheet 1 based
  33. string s = "";
  34. string sheetsFrom = "";
  35. string sheetFromTo = "";
  36. if (sheetFrom != null)
  37. {
  38. if (sheetFrom == "0")
  39. sheetFrom = "1";
  40. sheetsFrom = m_workSheets[sheetFrom].SheetName;
  41. }
  42. if (sheetTo != null)
  43. {
  44. if (sheetTo.ToString() == "0")
  45. sheetTo = "1";
  46. if (sheetsFrom.Length > 0)
  47. sheetFromTo = sheetsFrom + ":" + m_workSheets[sheetTo].SheetName;
  48. else
  49. sheetFromTo = m_workSheets[sheetTo].SheetName;
  50. }
  51. if (sheetFromTo.Length > 0 )
  52. s = sheetFromTo + "!" + Globals.ConvertColNumToString(columnFrom) + rowFrom.ToString() + ":" + Globals.ConvertColNumToString(columnTo) + rowTo.ToString();
  53. else
  54. s = Globals.ConvertColNumToString(columnFrom) + rowFrom.ToString() + ":" + Globals.ConvertColNumToString(columnTo) + rowTo.ToString();
  55. return s;
  56. }
  57. internal WorkSheetCollection ExcelWorkSheets
  58. {
  59. set
  60. {
  61. m_workSheets = value;
  62. }
  63. }
  64. #region IDisposable ³ÉÔ±
  65. public void Dispose()
  66. {
  67. m_workSheets = null;
  68. }
  69. #endregion
  70. }
  71. }