internal Column(SheetParser owner, int index, string name, CellParser parser) { Owner = owner; Index = index; Name = string.IsNullOrEmpty(name) ? index.ToString() : name; Parser = parser; }
public static void SheetToJsonFile(Sheet sheet, SheetParser parser, bool ignoreFirstRow, string jsonPath, ICollection <Cell> notParsedCells = null) { var jsonObject = SheetToJson(sheet, parser, ignoreFirstRow, notParsedCells); var jsonText = jsonObject.ToString(Formatting.Indented); File.WriteAllText(jsonPath, jsonText); }
public static JArray SheetToJson(Sheet sheet, SheetParser parser, bool ignoreFirstRow = false, ICollection <Cell> notParsedCells = null) { Ensure.Argument.NotNull(sheet, nameof(sheet)); Ensure.Argument.NotNull(parser, nameof(parser)); var json = new JArray(); foreach (var row in sheet.Rows) { if (ignoreFirstRow && row.Index == 0) { continue; } var jsonRow = new JObject(); foreach (var cell in row.Cells) { var value = cell.Value; if (!Index.IsValid(cell.ColumnIndex, parser.ColumnCount)) { notParsedCells?.Add(cell); continue; } var columnParser = parser[cell.ColumnIndex]; var jsonValue = columnParser.Parse(value); if (jsonValue != null) { jsonRow[columnParser.Name] = jsonValue; } else { notParsedCells?.Add(cell); } } json.Add(jsonRow); } return(json); }
public static void SheetToJsonFile(Sheet sheet, SheetParser parser, string jsonPath, ICollection <Cell> notParsedCells = null) { SheetToJsonFile(sheet, parser, false, jsonPath, notParsedCells); }