[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.ICsvParser

ICsvParser Interface

Represents a custom CSV parser.

Assign an implementation to the Parser property of CsvOpenOptions to inspect each parsed CSV cell and optionally modify the parsed value or number format.

Namespace: GrapeCity.Documents.Excel
Assembly: DS.Documents.Excel.dll
Syntax
public interface ICsvParser
Public Interface ICsvParser
Examples
CsvOpenOptions options = new CsvOpenOptions();
ICsvParser parser = new LeadingZeroParser();
options.Parser = parser;
string filePath = Path.Combine(Path.GetTempPath(), "source.csv");
File.WriteAllText(filePath, "Code\n0012");
workbook.Open(filePath, options);
IWorksheet activeSheet = workbook.ActiveSheet;

class LeadingZeroParser : ICsvParser
{
    public void Parse(CsvParseResult result, CsvParseContext context)
    {
        if (context.Text.StartsWith("00"))
        {
            result.Value = context.Text;
        }
    }
}

Methods

Name Description
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.