[]
A custom ICsvParser can inspect or modify this result to preserve leading zeros, convert text to another supported value, or assign a number format for the imported cell. Use setValue(Object) or setNumberFormat(String) to update the result contents.
CsvOpenOptions options = new CsvOpenOptions();
options.setParser(new ICsvParser() {
public void Parse(CsvParseResult result, CsvParseContext context) {
if (context.getText().endsWith("%")) {
String text = context.getText().replace("%", "");
result.setValue(Double.parseDouble(text) / 100);
result.setNumberFormat("0%");
}
}
});
workbook.open("path/to/percentage.csv", options);
CsvParseResult(Object value,
String numberFormat) getValue()voidsetNumberFormat(String numberFormat) voidvalue - The parsed value.numberFormat - The parsed number format.
CsvOpenOptions options = new CsvOpenOptions();
options.setParser(new ICsvParser() {
public void Parse(CsvParseResult result, CsvParseContext context) {
result.setValue(context.getText());
Object value = result.getValue();
}
});
workbook.open("path/to/data.csv", options);
Double, String, Boolean, or CalcError. Other data types are discarded.
CsvOpenOptions options = new CsvOpenOptions();
options.setParser(new ICsvParser() {
public void Parse(CsvParseResult result, CsvParseContext context) {
if (context.getText().startsWith("00")) {
result.setValue(context.getText());
}
}
});
workbook.open("path/to/data.csv", options);
value - The parsed value.
CsvOpenOptions options = new CsvOpenOptions();
options.setParser(new ICsvParser() {
public void Parse(CsvParseResult result, CsvParseContext context) {
if (context.getText().endsWith("%")) {
result.setNumberFormat("0%");
String numberFormat = result.getNumberFormat();
}
}
});
workbook.open("path/to/percentage.csv", options);
CsvOpenOptions options = new CsvOpenOptions();
options.setParser(new ICsvParser() {
public void Parse(CsvParseResult result, CsvParseContext context) {
if (context.getText().endsWith("%")) {
result.setNumberFormat("0%");
}
}
});
workbook.open("path/to/percentage.csv", options);
numberFormat - The parsed number format.