12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
-
- using CommonLang;
- using CommonLang.IO;
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.XSSF.UserModel;
- using System;
- using System.IO;
- using XmdsCommonServer.XLS.Data;
- namespace XmdsCommonServer.XLS
- {
- public class XLSZhanYaoDataLoader : XLSLoader
- {
- private HashMap<int, ZhanYaoData> ZhanYaoDatas = new HashMap<int, ZhanYaoData>();
- public XLSZhanYaoDataLoader(string path)
- {
- byte[] data = Resource.LoadData(path);
- if (data == null)
- {
- throw new Exception("Can not read xls file : " + path);
- }
- using (MemoryStream ms = new MemoryStream(data))
- {
- IWorkbook Workbook = null;
- if (path.Contains(".xlsx"))
- {
- Workbook = new XSSFWorkbook(ms);
- }
- else if (path.Contains(".xls"))
- {
- Workbook = new HSSFWorkbook(ms);
- }
- for (int si = 0; si < Workbook.NumberOfSheets; si++)
- {
- ISheet sheet = Workbook.GetSheetAt(si) as ISheet;
- try
- {
- if (sheet.SheetName == "Zhanyao_title")
- {
- LoadSheet(sheet);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSZhanYaoDataLoader 初始化斩妖配置错误SheetName = {0},Error = {1}",
- sheet.SheetName, error.ToString()));
- }
- }
- }
- log.Info("XLSZhanYaoDataLoader 初始化怪物配置完成.");
- }
- private void LoadSheet(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (ZhanYaoData m in LoadSheet<ZhanYaoData>(sheet))
- {
- ZhanYaoDatas.Add(m.Zhanyao_TitleLv, m);
- index++;
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSZhanYaoDataLoader Error : index = {0} Error = {1}", index, error.ToString()));
- }
- log.Info(string.Format("loadSheet【{0}】Complete", sheet.SheetName));
- }
- public ZhanYaoData GetZhanYaoData(int level)
- {
- return this.ZhanYaoDatas.Get(level);
- }
- }
- }
|