[]
自定义 ICsvParser 可以检查或修改此结果,以保留前导零、将文本转换为另一个受支持的值,或为导入的单元格指定数字格式。使用 setValue(Object) 或 setNumberFormat(String) 可以更新结果内容。
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);
value - 解析后的值。numberFormat - 解析后的数字格式。
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 或 CalcError。其他数据类型将被丢弃。
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 - 解析后的值。
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 - 解析后的数字格式。