XLSBSConfigLoader.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. 
  2. using CommonLang;
  3. using CommonLang.IO;
  4. using NPOI.HSSF.UserModel;
  5. using NPOI.SS.UserModel;
  6. using NPOI.XSSF.UserModel;
  7. using System;
  8. using System.IO;
  9. using XmdsCommonServer.XLS.Data;
  10. namespace XmdsCommonServer.XLS
  11. {
  12. public class XLSBSConfigLoader : XLSLoader
  13. {
  14. //多人,深渊秘境数值加成
  15. private AbyssMutilAddition mutilAbyssAddition;
  16. public XLSBSConfigLoader(string path)
  17. {
  18. byte[] data = Resource.LoadData(path);
  19. if (data == null)
  20. {
  21. throw new Exception("Can not read xls file : " + path);
  22. }
  23. using (MemoryStream ms = new MemoryStream(data))
  24. {
  25. IWorkbook Workbook = null;
  26. if (path.Contains(".xlsx"))
  27. {
  28. Workbook = new XSSFWorkbook(ms);
  29. }
  30. else if (path.Contains(".xls"))
  31. {
  32. Workbook = new HSSFWorkbook(ms);
  33. }
  34. for (int si = 0; si < Workbook.NumberOfSheets; si++)
  35. {
  36. ISheet sheet = Workbook.GetSheetAt(si) as ISheet;
  37. try
  38. {
  39. if (sheet.SheetName == "AbyssMutilAddition")
  40. {
  41. LoadSheet(sheet);
  42. }
  43. }
  44. catch (Exception error)
  45. {
  46. throw new Exception(string.Format("XLSRandomMonsterSkillLoader 初始化怪物配置错误SheetName = {0},Error = {1}",
  47. sheet.SheetName, error.ToString()));
  48. }
  49. }
  50. if(mutilAbyssAddition == null)
  51. {
  52. mutilAbyssAddition = new AbyssMutilAddition();
  53. }
  54. }
  55. log.Info("XLSRandomMonsterSkillLoader 初始化怪物配置完成.");
  56. }
  57. private void LoadSheet(ISheet sheet)
  58. {
  59. try
  60. {
  61. foreach (AbyssMutilAddition m in LoadSheet<AbyssMutilAddition>(sheet))
  62. {
  63. mutilAbyssAddition = m;
  64. break;
  65. }
  66. }
  67. catch (Exception error)
  68. {
  69. throw new Exception(string.Format("XLSRandomMonsterSkillLoader Error : index = {0} Error = {1}", 0, error.ToString()));
  70. }
  71. log.Info(string.Format("loadSheet【{0}】Complete", sheet.SheetName));
  72. }
  73. public AbyssMutilAddition GetMutilAbyssAddition()
  74. {
  75. return mutilAbyssAddition;
  76. }
  77. }
  78. }