private static WDBRow[] ReadRowFromSheet(ISheet sheet, WDBField[] fields) { List <WDBRow> rows = new List <WDBRow>(); bool isStarted = false; for (int i = sm_Style.RowStartIndex + WDBConst.MinRowCount; i < sm_Style.RowEndIndex; i++) { var cellValue = GetCellValue(sheet.GetRow(i).GetCell(sm_Style.ColumnStartIndex)); if (isStarted) { if (string.IsNullOrEmpty(cellValue) && cellValue == sm_Style.LineEndFlag) { break; } } else { if (!string.IsNullOrEmpty(cellValue) && cellValue == sm_Style.LineStartFlag) { isStarted = true; } } if (isStarted) { WDBRow row = ReadRowFromSheet(sheet, i, fields); if (row != null) { rows.Add(row); } } } return(rows.ToArray()); }
public static string WriteToLua(WDBSheet sheet, TargetPlatformType platformType) { if (sheet.FieldCount == 0 || sheet.RowCount == 0) { return(string.Empty); } WDBFieldPlatform platform = platformType == TargetPlatformType.Client ? WDBFieldPlatform.Client : WDBFieldPlatform.Server; StringBuilder builder = new StringBuilder(); int indent = 0; builder.AppendLine($"local {sheet.Name} = {{"); for (int r = 0; r < sheet.RowCount; r++) { WDBRow row = sheet.GetRowAtIndex(r); WDBField keyField = sheet.GetFieldAtIndex(0); WDBCell keyCell = row.GetCellByIndex(0); indent++; string keyStr = keyCell.GetContent(keyField); builder.AppendLine($"{GetIndent(indent)}[{keyStr}] = {{"); for (int f = 0; f < sheet.FieldCount; f++) { WDBField field = sheet.GetFieldAtIndex(f); if (string.IsNullOrEmpty(field.Name)) { continue; } if (field.FieldPlatform != WDBFieldPlatform.All && field.FieldPlatform != platform) { continue; } indent++; WDBCell cell = row.GetCellByIndex(f); AppendValueLine(builder, indent, field, cell); indent--; } builder.AppendLine($"{GetIndent(indent)}}},"); indent--; } builder.AppendLine("}"); builder.AppendLine($"return {sheet.Name}"); return(builder.ToString()); }
private static WDBRow ReadRowFromSheet(ISheet sheet, int dataRow, WDBField[] fields) { sm_LogHandler?.Invoke(LogType.Info, string.Format(LogMessage.INFO_START_READ_LINE, dataRow)); WDBRow row = new WDBRow(dataRow); IRow r = sheet.GetRow(dataRow); for (int i = 0; i < fields.Length; i++) { string cellValue = GetCellValue(r.GetCell(fields[i].Column)); row.AddCell(i, cellValue); } sm_LogHandler?.Invoke(LogType.Info, string.Format(LogMessage.INFO_CREATE_ROW, row)); sm_LogHandler?.Invoke(LogType.Info, string.Format(LogMessage.INFO_END_READ_ROW, dataRow)); return(row); }
public static string WriteToJson(WDBSheet sheet, TargetPlatformType platformType) { if (sheet.FieldCount == 0 || sheet.RowCount == 0) { return(string.Empty); } WDBFieldPlatform platform = platformType == TargetPlatformType.Client ? WDBFieldPlatform.Client : WDBFieldPlatform.Server; JObject sheetObject = new JObject(); for (int r = 0; r < sheet.RowCount; r++) { WDBRow row = sheet.GetRowAtIndex(r); JObject rowObject = new JObject(); for (int f = 0; f < sheet.FieldCount; f++) { WDBField field = sheet.GetFieldAtIndex(f); if (string.IsNullOrEmpty(field.Name)) { continue; } if (field.FieldPlatform != WDBFieldPlatform.All && field.FieldPlatform != platform) { continue; } object value = GetValue(field, row.GetCellByIndex(f)); rowObject.Add(field.Name, JToken.FromObject(value)); if (f == 0) { sheetObject.Add(value.ToString(), rowObject); } } } return(sheetObject.ToString(Formatting.Indented)); }