using Aspose.Cells; using NLog; namespace Server.Git { class ExcelManager { private static readonly NLog.ILogger logger = LogManager.GetCurrentClassLogger(); public class sheet { string _name; public string name { get { return _name; } } List _variable; public List variable { get { return _variable; } } List _type; public List type { get { return _type; } } Dictionary> _dicViewer; public Dictionary> dicViewer { get { return _dicViewer; } } public sheet(string name, List variable, List type, Dictionary> dicViewer) { this._name = name; this._variable = variable; this._type = type; this._dicViewer = dicViewer; } } List _sheets; public List sheets { get { return _sheets; } } string _pathFile; public ExcelManager(string path, string file) { _pathFile = path + "\\" + file; } public bool Play() { return ExcelLoad(_pathFile); } public bool ExcelLoad(string path)//엑셀 로드 { // 엑셀 파일 불러오기 Workbook wb = new Workbook(_pathFile); // 모든 워크시트 가져오기 WorksheetCollection collection = wb.Worksheets; _sheets = new List(); // 모든 워크시트 반복 try { for (int worksheetIndex = 0; worksheetIndex < collection.Count; worksheetIndex++) { //변수이름 List variable = new List(); //변수 타입 List type = new List(); Dictionary> dicViewer = new Dictionary>(); // 인덱스를 사용하여 워크시트 가져오기 Worksheet worksheet = collection[worksheetIndex]; // 행과 열의 수 얻기 int vertical = worksheet.Cells.MaxDataRow; int horizontal = worksheet.Cells.MaxDataColumn; //변수 이름과 타입 삽입 for (int n = 0; n <= horizontal; n++) { // Console.Write(worksheet.Cells[i, j].Value + " | "); variable.Add((string)worksheet.Cells[0, n].Value); type.Add(((string)worksheet.Cells[2, n].Value).ToLower()); } for (int n = 3; n <= vertical; n++) { List dataList = new List(); for (int m = 0; m <= horizontal; m++) { switch (type[m]) { case "enum": case "int": dataList.Add(worksheet.Cells[n, m].Value); break; case "string": case "text": case "time": dataList.Add(worksheet.Cells[n, m].Value); break; default: Console.WriteLine("알수없는 타입의 메세지 입니다."); break; } } dicViewer.Add(n, dataList); } sheet sheet = new sheet(worksheet.Name, variable, type, dicViewer); _sheets.Add(sheet); } } catch (Exception ex) { logger.Error(ex); return false; } return true; } } }