[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.ICsvParser.Parse

Parse Method

Parse(CsvParseResult, CsvParseContext)

Parses cell text and lets you inspect or modify the result produced by the built-in parser.

Use Text to inspect the original CSV text, and use Value or NumberFormat to customize the imported value.

Declaration
void Parse(CsvParseResult result, CsvParseContext context)
Sub Parse(result As CsvParseResult, context As CsvParseContext)
Parameters
Type Name Description
CsvParseResult result

The parsed result produced by the built-in parser.

CsvParseContext context

The parse context of the current cell.

Examples
ICsvParser parser = new PercentParser();
CsvOpenOptions options = new CsvOpenOptions();
options.Parser = parser;
string filePath = Path.Combine(Path.GetTempPath(), "percentage.csv");
File.WriteAllText(filePath, "Value\n15%");
workbook.Open(filePath, options);
IWorksheet activeSheet = workbook.ActiveSheet;

class PercentParser : ICsvParser
{
    public void Parse(CsvParseResult result, CsvParseContext context)
    {
        if (context.Text.EndsWith("%"))
        {
            string text = context.Text.Replace("%", "");
            result.Value = double.Parse(text) / 100;
            result.NumberFormat = "0%";
        }
    }
}