[]
Use this class to configure how CSV content is interpreted when it is opened, including column separator, row separator, and quote character, encoding, numeric and date conversion, formula recognition, parsed-value styling, and a custom ICsvParser.
Instances of this class use OpenFileFormat.Csv as the target format.
byte[] csvBytes = "Name,Value\r\nTest,001".getBytes(StandardCharsets.UTF_8);
CsvOpenOptions options = new CsvOpenOptions();
options.setColumnSeparator(",");
options.setConvertNumericData(false);
workbook.open(new ByteArrayInputStream(csvBytes), options);
Object cellValue = workbook.getWorksheets().get(0).getRange("B2").getValue();
final charfinal Stringfinal booleanfinal booleanfinal Stringfinal boolean"=" is treated as a formula when a CSV file is opened.final booleanfinal Stringfinal Stringfinal voidsetCellSeparator(char value) final voidsetColumnSeparator(String value) final voidsetConvertDateTimeData(boolean value) final voidsetConvertNumericData(boolean value) final voidsetEncoding(String value) final voidsetHasFormula(boolean value) "=" is treated as a formula when a CSV file is opened.voidsetParser(ICsvParser parser) final voidsetParseStyle(boolean value) final voidsetRowSeparator(String value) final voidsetSeparatorString(String value) setColumnSeparator(String) instead.getFileFormat, setFileFormatCsvOpenOptions instance for opening CSV files.This constructor initializes the options with the CSV file format and creates the internal option data used to control CSV parsing behavior, such as numeric and date conversion, separators, and encoding.
byte[] csvBytes = "Name,Value\r\nTest,001".getBytes(StandardCharsets.UTF_8);
CsvOpenOptions options = new CsvOpenOptions();
options.setConvertNumericData(false);
options.setColumnSeparator(",");
workbook.open(new ByteArrayInputStream(csvBytes), options);
Object cellValue = workbook.getWorksheets().get(0).getRange("B2").getValue();
The default value is true. When this property is true, text that can be recognized as numeric data is converted during CSV import.
CsvOpenOptions options = new CsvOpenOptions();
options.setConvertNumericData(false);
boolean convertNumericData = options.getConvertNumericData();
workbook.open("path/to/source.csv", options);
true if strings in the text file are converted to numeric data during CSV import; otherwise, false.The default value is true. When this property is true, text that can be recognized as numeric data is converted during CSV import.
CsvOpenOptions options = new CsvOpenOptions();
options.setConvertNumericData(false);
workbook.open("path/to/source.csv", options);
value - true if strings in the text file are converted to numeric data during CSV import; otherwise, false.The default value is true. When this property is true, text that can be recognized as date or time data is converted during CSV import.
CsvOpenOptions options = new CsvOpenOptions();
options.setConvertDateTimeData(false);
boolean convertDateTimeData = options.getConvertDateTimeData();
workbook.open("path/to/data.csv", options);
true if strings in the text file are converted to date data during CSV import; otherwise, false.The default value is true. When this property is true, text that can be recognized as date or time data is converted during CSV import.
CsvOpenOptions options = new CsvOpenOptions();
options.setConvertDateTimeData(false);
workbook.open("path/to/data.csv", options);
value - true if strings in the text file are converted to date data during CSV import; otherwise, false.The column separator determines how fields are split in each row when a CSV file is opened. The default value is ",". Use setColumnSeparator(String) to change it before opening a CSV file.
When opening CSV content, the column separator, row separator, and quote character must be distinct and must not contain one another.
CsvOpenOptions options = new CsvOpenOptions();
options.setColumnSeparator(",");
String separator = options.getColumnSeparator();
workbook.open("path/to/source.csv", options);
When opening CSV content, the column separator, row separator, and quote character must be distinct and must not contain one another.
CsvOpenOptions options = new CsvOpenOptions();
options.setColumnSeparator(",");
workbook.open("path/to/source.csv", options);
value - The current column separator string.The row separator is the string delimiter that separates records in the source CSV data.
When opening CSV content, the column separator, row separator, and quote character must be distinct and must not contain one another.
CsvOpenOptions options = new CsvOpenOptions();
options.setRowSeparator("\r\n");
String rowSeparator = options.getRowSeparator();
workbook.open("path/to/source.csv", options);
The row separator is the string delimiter that separates records in the source CSV data.
When opening CSV content, the column separator, row separator, and quote character must be distinct and must not contain one another.
CsvOpenOptions options = new CsvOpenOptions();
options.setRowSeparator("\r\n");
workbook.open("path/to/source.csv", options);
value - The row separator string for CSV parsing.The default value is '"'.
When opening CSV content, the column separator, row separator, and quote character must be distinct and must not contain one another.
CsvOpenOptions options = new CsvOpenOptions();
options.setCellSeparator('\'');
char cellSeparator = options.getCellSeparator();
workbook.open("path/to/source.csv", options);
The default value is '"'.
When opening CSV content, the column separator, row separator, and quote character must be distinct and must not contain one another.
CsvOpenOptions options = new CsvOpenOptions();
options.setCellSeparator('\'');
workbook.open("path/to/source.csv", options);
value - The quote character used to enclose quoted cell text in CSV content.setColumnSeparator(String) instead.This method is deprecated. Use setColumnSeparator(String) instead.
value - The column separator string.getColumnSeparator() instead.This method is deprecated. Use getColumnSeparator() instead.
The default value is utf-8.
CsvOpenOptions options = new CsvOpenOptions();
options.setEncoding("utf-8");
String encoding = options.getEncoding();
workbook.open("path/to/source.csv", options);
The default value is utf-8.
CsvOpenOptions options = new CsvOpenOptions();
options.setEncoding("utf-8");
workbook.open("path/to/source.csv", options);
value - The default encoding name for opening a CSV file.The default value is true. Use setParseStyle(boolean) to control whether style information is applied during parsing.
CsvOpenOptions options = new CsvOpenOptions();
options.setParseStyle(false);
boolean parseStyle = options.getParseStyle();
workbook.open("path/to/source.csv", options);
true if styles are applied to parsed numeric or date/time values; otherwise, false.
CsvOpenOptions options = new CsvOpenOptions();
options.setParseStyle(false);
workbook.open("path/to/source.csv", options);
value - true if styles are applied to parsed numeric or date/time values; otherwise, false."=" is treated as a formula when a CSV file is opened.The default value is true.
CsvOpenOptions options = new CsvOpenOptions();
options.setHasFormula(false);
boolean hasFormula = options.getHasFormula();
workbook.open("path/to/data.csv", options);
true if text that starts with "=" is treated as a formula when opening a CSV file; otherwise, false."=" is treated as a formula when a CSV file is opened.The default value is true.
CsvOpenOptions options = new CsvOpenOptions();
options.setHasFormula(false);
workbook.open("path/to/data.csv", options);
value - true if text that starts with "=" is treated as a formula when opening a CSV file; otherwise, false.The parser is called for each parsed CSV cell and can inspect the original text or modify the imported value and number format.
CsvOpenOptions options = new CsvOpenOptions();
ICsvParser parser = new ICsvParser() {
public void Parse(CsvParseResult result, CsvParseContext context) {
result.setValue(context.getText());
}
};
options.setParser(parser);
ICsvParser customParser = options.getParser();
workbook.open("path/to/source.csv", options);
The parser is called for each parsed CSV cell and can inspect the original text or modify the imported value and number format.
CsvOpenOptions options = new CsvOpenOptions();
class LeadingZeroParser implements ICsvParser {
public void Parse(CsvParseResult csvParseResult, CsvParseContext context) {
if (context.getText().startsWith("00")) {
csvParseResult.setValue(context.getText());
}
}
}
options.setParser(new LeadingZeroParser());
workbook.open("path/to/data.csv", options);
parser - The custom parser to use when opening CSV content.
getColumnSeparator()instead.