[]
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.
void Parse(CsvParseResult result, CsvParseContext context)
Sub Parse(result As CsvParseResult, context As CsvParseContext)
| Type | Name | Description |
|---|---|---|
| CsvParseResult | result | The parsed result produced by the built-in parser. |
| CsvParseContext | context | The parse context of the current cell. |
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%";
}
}
}