[]
        
(Showing Draft Content)

CsvSaveOptions

Class CsvSaveOptions

java.lang.Object
com.grapecity.documents.excel.SaveOptionsBase
com.grapecity.documents.excel.CsvSaveOptions

public class CsvSaveOptions extends SaveOptionsBase
Represents options for saving a workbook as a CSV file.

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);
 
  • Constructor Details

    • CsvSaveOptions

      public CsvSaveOptions()
      Creates options for saving a workbook as a CSV file.

      This 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);
       
  • Method Details

    • getColumnSeparator

      public final String getColumnSeparator()
      Gets the column separator used when saving CSV data.

      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);
       
      Returns:
      The current column separator string.
    • setColumnSeparator

      public final void setColumnSeparator(String value)
      Sets the column separator used when saving CSV data.
      
       CsvSaveOptions options = new CsvSaveOptions();
       options.setColumnSeparator(";");
       workbook.save("path/to/output.csv", options);
       
      Parameters:
      value - The current column separator string.
    • getRowSeparator

      public final String getRowSeparator()
      Gets the row separator.

      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);
       
      Returns:
      The row separator string.
    • setRowSeparator

      public final void setRowSeparator(String value)
      Sets the row separator.

      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);
       
      Parameters:
      value - The row separator string.
    • getCellSeparator

      public final char getCellSeparator()
      Gets the cell separator character used when saving CSV content.

      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);
       
      Returns:
      The cell separator character used for CSV export.
    • setCellSeparator

      public final void setCellSeparator(char value)
      Sets the cell separator character used when saving CSV content.

      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);
       
      Parameters:
      value - The cell separator character used for CSV export.
    • setSeparatorString

      @Deprecated public final void setSeparatorString(String value)
      Deprecated.
      Sets the column separator string.

      This method is deprecated and Sets the same value as getColumnSeparator(). By default, the separator is a comma.

      Parameters:
      value - The column separator string.
    • getSeparatorString

      @Deprecated public final String getSeparatorString()
      Deprecated.
      Gets the column separator string.

      This method is deprecated and returns the same value as getColumnSeparator(). By default, the separator is a comma.

      Returns:
      The column separator string.
    • getEncoding

      public final String getEncoding()
      Gets the default encoding used when saving a CSV file.

      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);
       
      Returns:
      The default encoding name.
    • setEncoding

      public final void setEncoding(String value)
      Sets the default encoding used when saving a CSV file.

      The default encoding is utf-8.

      
       CsvSaveOptions options = new CsvSaveOptions();
       options.setEncoding("UTF-16");
       workbook.save("path/to/output.csv", options);
       
      Parameters:
      value - The default encoding name.
    • getValueQuoteType

      public final ValueQuoteType getValueQuoteType()
      Gets how values are quoted in the exported text file.

      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);
       
      Returns:
      The value quoting mode for exported text files.
    • setValueQuoteType

      public final void setValueQuoteType(ValueQuoteType value)
      Sets how values are quoted in the exported text file.

      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);
       
      Parameters:
      value - The value quoting mode to apply. If getQuoteColumns() is set, this value is ignored during CSV export. Null behavior is not specified.
    • getTrimLeadingBlankRowAndColumn

      public final boolean getTrimLeadingBlankRowAndColumn()
      Gets whether leading blank rows and columns are trimmed when saving to CSV.

      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);
       
      Returns:
      true if leading blank rows and columns are trimmed during CSV export; otherwise, false.
    • setTrimLeadingBlankRowAndColumn

      public final void setTrimLeadingBlankRowAndColumn(boolean value)
      Sets whether leading blank rows and columns are trimmed when saving to CSV.

      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);
       
      Parameters:
      value - true if leading blank rows and columns are trimmed during CSV export; otherwise, false.
    • getEscapeFormulaLikeValues

      public final boolean getEscapeFormulaLikeValues()
      Gets whether CSV values that begin with formula-like characters are escaped during export.

      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);
       
      Returns:
      true if formula-like CSV values are escaped during export; otherwise, false.
    • setEscapeFormulaLikeValues

      public final void setEscapeFormulaLikeValues(boolean value)
      Sets whether CSV values that begin with formula-like characters are escaped during export.

      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);
       
      Parameters:
      value - true if formula-like CSV values are escaped during export; otherwise, false.
    • setQuoteColumns

      public final void setQuoteColumns(int[] value)
      Sets the zero-based column indices that are configured to be quoted during CSV export.
      
       CsvSaveOptions options = new CsvSaveOptions();
       options.setQuoteColumns(new int[] { 1, 3, 4 });
       workbook.save("path/to/output.csv", options);
       
      Parameters:
      value - An array of zero-based column indices to quote, or null if no specific columns have been configured.
    • getQuoteColumns

      public final int[] getQuoteColumns()
      Gets the zero-based column indices that are configured to be quoted during CSV export.

      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);
       
      Returns:
      An array of zero-based column indices to quote, or null if no specific columns have been configured.
    • toString

      public String toString()
      Returns a string representation of these CSV save options.
      Overrides:
      toString in class Object
      Returns:
      A string representation of these CSV save options.