private string ProcessSheet(string exls_name, ISheet sheet) { ExcelFileName = exls_name; ExcelSheetName = sheet.SheetName; // 第一行 记录列数 记录列描述 IRow row1 = sheet.GetRow(0); // 第一个单元格不是array字段,该表不需要导出 if (row1 == null) { return(string.Empty); } var cell011 = row1.GetCell(0); if (cell011 == null || cell011.StringCellValue != "array") { return(string.Empty); } int colums = 0; foreach (var cell in row1.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } ColumDescMap.Add(cell.Address.Column, cell.ToString()); colums++; } int TotalRowCount = sheet.LastRowNum; if (TotalRowCount < 5) { Console.Error.WriteLine("Excel文件格式不正确行数过少"); return(string.Empty); } IRow row2 = sheet.GetRow(1); int type_colums_count = 0; foreach (var cell in row2.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } type_colums_count++; // ColumType.Add(cell.ToString()); ColumTypeMap.Add(cell.Address.Column, cell.ToString()); } IRow row3 = sheet.GetRow(2); int srv_colums_count = 0; foreach (var cell in row3.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } srv_colums_count++; } IRow row4 = sheet.GetRow(3); // client 导出标记 int clt_colums_count = 0; foreach (var cell in row4.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } clt_colums_count++; // ColumCltField.Add(cell.ToString()); ColumCltFieldMap.Add(cell.Address.Column, cell.ToString()); } ProcessSheetFields(exls_name, sheet.SheetName, row4, row1, row2); SheetIds.Clear(); for (int row = Define.StartRowIndex; row <= TotalRowCount; row++) { IRow rowData = sheet.GetRow(row); if (rowData != null) //null is when the row only contains empty cells { //MessageBox.Show(string.Format("Row {0} = {1}", row, sheet.GetRow(row).GetCell(0).StringCellValue)); ICell cell0 = rowData.GetCell(0); if (cell0 != null && cell0.ToString().StartsWith("##")) { Console.WriteLine(string.Format("Ignore Sheet {0} Row {1}.", sheet.SheetName, row)); } else { if (exls_name.Equals("characters_red") && sheet.SheetName.Equals("skill")) { CheckCharacterRowJsonConfig(row1, rowData, 6, 9); // effect_id, hit_data CheckCharacterRowJsonConfig(row1, rowData, 6, 10); // effect_id, hit_time CheckCharacterRowJsonConfig(row1, rowData, 6, 5); // effect_id, target_relation } table_data += ProcessRow(row, rowData); } } } string table_name = exls_name + "_" + sheet.SheetName; string content = string.Format(Define.TABLE_DATA_TEMP, table_data, table_name); //Console.WriteLine(content); return(content); //WriteLuaFile(content, table_name + ".lua"); }
private string ProcessSheet(string exls_name, ISheet sheet) { ExcelFileName = exls_name; ExcelSheetName = sheet.SheetName; // 第一行 记录列数 记录列描述 IRow row1 = sheet.GetRow(0); // 第一个单元格不是array字段,该表不需要导出 if (row1 == null) { return(string.Empty); } var cell011 = row1.GetCell(0); if (cell011 == null || cell011.StringCellValue != "array") { return(string.Empty); } int colums = 0; foreach (var cell in row1.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } ColumDescMap.Add(cell.Address.Column, cell.ToString()); colums++; } int TotalRowCount = sheet.LastRowNum; if (TotalRowCount < 5) { Console.Error.WriteLine("Excel文件格式不正确行数过少"); return(string.Empty); } IRow row2 = sheet.GetRow(1); int type_colums_count = 0; foreach (var cell in row2.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } type_colums_count++; // ColumType.Add(cell.ToString()); ColumTypeMap.Add(cell.Address.Column, cell.ToString()); } IRow row3 = sheet.GetRow(2); int srv_colums_count = 0; foreach (var cell in row3.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } srv_colums_count++; } IRow row4 = sheet.GetRow(3); // client 导出标记 int clt_colums_count = 0; foreach (var cell in row4.Cells) { if (cell == null || cell.CellType == CellType.Blank) { continue; } clt_colums_count++; // ColumCltField.Add(cell.ToString()); ColumCltFieldMap.Add(cell.Address.Column, cell.ToString()); } ProcessSheetFields(exls_name, sheet.SheetName, row4, row1, row2); SheetIds.Clear(); Dictionary <int, Dictionary <string, object> > keyValuePairsSheet = new Dictionary <int, Dictionary <string, object> >(); for (int row = Define.StartRowIndex; row <= TotalRowCount; row++) { IRow rowData = sheet.GetRow(row); if (rowData != null) //null is when the row only contains empty cells { //MessageBox.Show(string.Format("Row {0} = {1}", row, sheet.GetRow(row).GetCell(0).StringCellValue)); ICell cell0 = rowData.GetCell(0); if (cell0 != null && cell0.ToString().StartsWith("##")) { Console.WriteLine(string.Format("Ignore Sheet {0} Row {1}.", sheet.SheetName, row)); } else { var id = (int)(rowData.GetCell(1).NumericCellValue); var rowDic = ProcessRow(row, rowData); keyValuePairsSheet.Add(id, rowDic); } } } return(JsonConvert.SerializeObject(keyValuePairsSheet)); }