static void Example2() { var csvOptions = new CsvLoadOptions(CsvType.CommaDelimited) { AllowNewLineInQuotes = true, HasQuotedValues = true, HasFormulas = true }; // Read CSV file using specified CsvLoadOptions. var workbook = ExcelFile.Load("ArtificalObjectsOnMoon.csv", csvOptions); // Calculate Excel formulas from CSV data. var worksheet = workbook.Worksheets[0]; worksheet.Calculate(); // Iterate through read CSV records. foreach (var row in worksheet.Rows) { // Iterate through read CSV fields. foreach (var cell in row.AllocatedCells) { // Display just the first line of text from Excel cell. var value = cell.Value?.ToString() ?? string.Empty; Console.Write($"{value.Split('\n')[0],-25}"); } Console.WriteLine(); } }
public static ExcelFile ReadFile(string path, CsvLoadOptions options) { var workbook = new ExcelFile(); int sheetIndex = 0; using (var reader = new LargeCsvReader(path, options)) while (reader.CanReadNextSheet()) { reader.ReadSheet(workbook, $"Sheet{++sheetIndex}"); } return(workbook); }
public static void Run() { string outputFolder = Constants.GetOutputDirectoryPath(); string outputFile = Path.Combine(outputFolder, "converted.json"); var loadOptions = new CsvLoadOptions { Separator = ',' }; using (Converter converter = new Converter(Constants.SAMPLE_CSV, () => loadOptions)) { DataConvertOptions options = new DataConvertOptions { Format = DataFileType.Json }; converter.Convert(outputFile, options); } Console.WriteLine("\nDocument converted successfully. \nCheck output in {0}", outputFolder); }
private LargeCsvReader(string path, CsvLoadOptions options) { this.reader = File.OpenText(path); this.options = options; }