[]
Use this class to configure CSV export settings such as column, row, and cell separators, text encoding, value quoting, and whether leading blank rows and columns are trimmed. An instance of this class can be passed to Workbook.save(String,SaveOptionsBase) when saving CSV content.
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
CsvSaveOptions options = new CsvSaveOptions();
options.setColumnSeparator(";");
options.setRowSeparator("\r\n");
options.setCellSeparator('"');
options.setValueQuoteType(ValueQuoteType.Always);
workbook.save("path/to/output.csv", options);
final charfinal Stringfinal Stringfinal booleanfinal int[]final Stringfinal Stringfinal booleanfinal ValueQuoteTypefinal voidsetCellSeparator(char value) final voidsetColumnSeparator(String value) final voidsetEncoding(String value) final voidsetEscapeFormulaLikeValues(boolean value) final voidsetQuoteColumns(int[] value) final voidsetRowSeparator(String value) final voidsetSeparatorString(String value) getColumnSeparator() instead.final voidsetTrimLeadingBlankRowAndColumn(boolean value) final voidsetValueQuoteType(ValueQuoteType value) toString()getFileFormat, setFileFormatThis constructor initializes the option object to use SaveFileFormat.Csv. Configure CSV-specific settings before passing the options to a workbook save API.
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
CsvSaveOptions options = new CsvSaveOptions();
options.setColumnSeparator(";");
options.setRowSeparator("\r\n");
options.setCellSeparator('"');
options.setValueQuoteType(ValueQuoteType.Always);
workbook.save("path/to/output.csv", options);
The column separator determines how values are separated between columns in the exported CSV content. Use setColumnSeparator(String) to change the separator before saving.
CsvSaveOptions options = new CsvSaveOptions();
options.setColumnSeparator(";");
String separator = options.getColumnSeparator();
workbook.save("path/to/output.csv", options);
CsvSaveOptions options = new CsvSaveOptions();
options.setColumnSeparator(";");
workbook.save("path/to/output.csv", options);
value - The current column separator string.Returns the string used to separate rows when saving a workbook to a CSV file.
CsvSaveOptions options = new CsvSaveOptions();
options.setRowSeparator("\r\n");
String separator = options.getRowSeparator();
workbook.save("path/to/output.csv", options);
Sets the string used to separate rows when saving a workbook to a CSV file.
CsvSaveOptions options = new CsvSaveOptions();
options.setRowSeparator("\r\n");
workbook.save("path/to/output.csv", options);
value - The row separator string.This character is used to enclose cell text in the exported CSV data. The default value is '\"'.
CsvSaveOptions options = new CsvSaveOptions();
options.setCellSeparator('\'');
char cellSeparator = options.getCellSeparator();
workbook.save("path/to/output.csv", options);
This character is used to enclose cell text in the exported CSV data. The default value is '\"'.
CsvSaveOptions options = new CsvSaveOptions();
options.setCellSeparator('\'');
workbook.save("path/to/output.csv", options);
value - The cell separator character used for CSV export.getColumnSeparator() instead.This method is deprecated and Sets the same value as getColumnSeparator(). By default, the separator is a comma.
value - The column separator string.getColumnSeparator() instead.This method is deprecated and returns the same value as getColumnSeparator(). By default, the separator is a comma.
The default encoding is utf-8.
CsvSaveOptions options = new CsvSaveOptions();
options.setEncoding("UTF-16");
String encoding = options.getEncoding();
workbook.save("path/to/output.csv", options);
The default encoding is utf-8.
CsvSaveOptions options = new CsvSaveOptions();
options.setEncoding("UTF-16");
workbook.save("path/to/output.csv", options);
value - The default encoding name.This option controls the quoting behavior used when saving CSV content. If getQuoteColumns() is set, this setting is ignored.
CsvSaveOptions options = new CsvSaveOptions();
options.setValueQuoteType(ValueQuoteType.Always);
ValueQuoteType quoteType = options.getValueQuoteType();
workbook.save("path/to/output.csv", options);
Use this property to control the quoting behavior for CSV export, such as quoting all values, quoting only values that contain special characters, or not quoting values. If getQuoteColumns() is set, this setting is ignored during export.
CsvSaveOptions options = new CsvSaveOptions();
options.setValueQuoteType(ValueQuoteType.Normal);
workbook.save("path/to/output.csv", options);
value - The value quoting mode to apply. If getQuoteColumns() is set, this value is ignored during CSV export. Null behavior is not specified.This property indicates whether leading blank rows and columns are trimmed in the same way as Microsoft Excel during CSV export. The default value is true.
CsvSaveOptions options = new CsvSaveOptions();
options.setTrimLeadingBlankRowAndColumn(false);
boolean trim = options.getTrimLeadingBlankRowAndColumn();
workbook.save("path/to/output.csv", options);
true if leading blank rows and columns are trimmed during CSV export; otherwise, false.This property indicates whether leading blank rows and columns are trimmed in the same way as Microsoft Excel during CSV export. The default value is true.
CsvSaveOptions options = new CsvSaveOptions();
options.setTrimLeadingBlankRowAndColumn(false);
workbook.save("path/to/output.csv", options);
value - true if leading blank rows and columns are trimmed during CSV export; otherwise, false.When this property is set to true, values that start with =, +, -, @, their full-width variants, tab, carriage return, or line feed are written with a leading apostrophe. The default value is false.
CsvSaveOptions options = new CsvSaveOptions();
options.setEscapeFormulaLikeValues(true);
boolean escape = options.getEscapeFormulaLikeValues();
workbook.save("path/to/output.csv", options);
true if formula-like CSV values are escaped during export; otherwise, false.When this property is set to true, values that start with =, +, -, @, their full-width variants, tab, carriage return, or line feed are written with a leading apostrophe. The default value is false.
CsvSaveOptions options = new CsvSaveOptions();
options.setEscapeFormulaLikeValues(true);
workbook.save("path/to/output.csv", options);
value - true if formula-like CSV values are escaped during export; otherwise, false.
CsvSaveOptions options = new CsvSaveOptions();
options.setQuoteColumns(new int[] { 1, 3, 4 });
workbook.save("path/to/output.csv", options);
value - An array of zero-based column indices to quote, or null if no specific columns have been configured.When setQuoteColumns(int[]) is used, only the specified columns are forced to use the cell separator as quotes, while other columns are not quoted unless required by the CSV content. Invalid column indices are preserved in this array, but they have no effect during export.
CsvSaveOptions options = new CsvSaveOptions();
options.setQuoteColumns(new int[] { 1, 3, 4 });
int[] quoteColumns = options.getQuoteColumns();
workbook.save("path/to/output.csv", options);
null if no specific columns have been configured.
getColumnSeparator()instead.