示例#1
0
 public ExcelDataItem(ExcelDataConfig config, int id, string header)
 {
     this.config = config;
     this.id     = id;
     this.header = header;
     this.items  = new Dictionary <KeyValuePair <int, string>, ExcelDataItem>();
 }
示例#2
0
 public SearchResult(ExcelDataConfig config, List <string> dataList)
 {
     this.config        = config;
     this.itemName      = dataList[EXCEL_DATA.ID.ToInt()] + "_" + dataList[EXCEL_DATA.ID.ToInt()];
     this.excelDataList = dataList;
 }
示例#3
0
        public void ReadExcel2Templ(TableUnitConfig table, string path, string configAlias)
        {
            Workbook wb;

            try
            {
                wb = new Workbook(path);
            }
            catch (Exception e)
            {
                throw new DataException(ERROR_CODE.OPEN_EXCEL_FAILED_WHEN_READ_EXCEL, string.Format("excel read failed:alias={0},path={1},error={2}", table.alias, path, e.Message));
            }
            var st = wb.Worksheets[table.alias];

            if (st == null)
            {
                throw new DataException(ERROR_CODE.LACK_EXCEL_SHEET, string.Format("excel do not have {0} sheet,path={1}", table.alias, path));
            }
            var sectionList = table.GetExcelTitles();

            if (sectionList.Count <= ExcelConfig.Instance.defaultTitles.Count)
            {
                throw new DataException(ERROR_CODE.EXCEL_TITLES_NO_DATA, string.Format("excel titles no data:alias={0},path={1}", table.alias, path));
            }
            var data = new ExcelDataConfig(table.alias, configAlias);

            for (int i = 0; i < sectionList.Count; ++i)
            {
                var colIndex = i + 1;
                var section  = sectionList[i];
                var cell     = st.Cells[ExcelConst.TITLE_ROW, colIndex];
                if (cell == null || cell.Value.ToString() != section.title)
                {
                    throw new DataException(ERROR_CODE.EXCEL_TITLE_NOT_MATCH_DEFINE, string.Format("excel title not match define:alias={0},path={1},columnIndex={2}", table.alias, path, colIndex + 1));
                }
                //加入标题信息
                data.titles.Add(new ExcelDataTitleConfig()
                {
                    alias = section.title, type = section.typeAlias
                });
            }
            for (int row = ExcelConst.TITLE_ROW + 1; row < st.Cells.MaxDataRow; ++row)
            {
                var idCell = st.Cells[row, 1];
                if (idCell == null || !int.TryParse(idCell.Value.ToString(), out int id))
                {
                    throw new DataException(ERROR_CODE.EXCEL_DATA_ID_INVALID, string.Format("excel id invalid:alias={0},path={1},rowIndex={2}", table.alias, path, row + 1));
                }
                var lineData = new List <string>();
                for (int col = 0; col < sectionList.Count; ++col)
                {
                    var realCol   = col + 1;
                    var cell      = st.Cells[row, realCol];
                    var cellValue = cell == null ? string.Empty : cell.Value.ToString();
                    lineData.Add(cellValue);
                }
                data.data[id] = lineData;
            }
            string templInfoPath = TableGlobalConfig.Instance.tableTemplDataPath + table.name + ".lua";

            try
            {
                data.WriteToFile(templInfoPath);
            }
            catch (Exception e)
            {
                throw new DataException(ERROR_CODE.EXCEL_INFO_WRITE_TO_FILE_FAILED, string.Format("excel info write to tempinfo file failed:alias={0},path={1},templInfoPath={2},error=[{3}]", table.alias, path, templInfoPath, e.Message));
            }
        }