Class CsvOptions

java.lang.Object
io.keikai.axyra.sheets.io.CsvOptions

public final class CsvOptions extends Object
Options for Workbook.saveCsv(path, options). The defaults write what a plain save("x.csv") writes, which is what Excel's Save As CSV writes: the active sheet, comma-separated, as display text.

The file is UTF-8 and every row ends with CR LF. CsvOptions.Values.RAW changes only numeric cells; text, booleans and errors are written the same way in both modes. A formula cell writes its cached value, never the formula.


 wb.saveCsv(path, CsvOptions.create().sheet("Payments").values(CsvOptions.Values.RAW));
 
  • Constructor Details

    • CsvOptions

      public CsvOptions()
  • Method Details

    • create

      public static CsvOptions create()
      Options with the defaults: the active sheet, comma, display text, no byte-order mark.
      Returns:
      new options
    • sheet

      public CsvOptions sheet(int index)
      Chooses the sheet to write by 0-based index, replacing a choice by name. Default: the active sheet, or the first visible sheet when the active sheet is hidden. A hidden sheet chosen by index is written.
      Parameters:
      index - the 0-based sheet index; an index past the last sheet makes saveCsv throw AxyraException
      Returns:
      these options
      Throws:
      IllegalArgumentException - if index is negative
    • sheet

      public CsvOptions sheet(String name)
      Chooses the sheet to write by name, compared ignoring case as Excel does. Replaces a choice by index.
      Parameters:
      name - the sheet name; an unknown name makes saveCsv throw IllegalArgumentException
      Returns:
      these options
      Throws:
      NullPointerException - if name is null
    • delimiter

      public CsvOptions delimiter(char delimiter)
      Sets the field separator. Default ','. A field that contains the separator, a double quote, a tab or a line break is quoted.
      Parameters:
      delimiter - one ASCII character, e.g. ';' or '\t'
      Returns:
      these options
      Throws:
      IllegalArgumentException - if delimiter is not ASCII, or is a double quote, CR or LF
    • values

      public CsvOptions values(CsvOptions.Values values)
      Chooses how numeric cells are written: display text (CsvOptions.Values.FORMATTED, the default) or stored values (CsvOptions.Values.RAW).
      Parameters:
      values - the mode
      Returns:
      these options
      Throws:
      NullPointerException - if values is null
    • utf8Bom

      public CsvOptions utf8Bom(boolean bom)
      Starts the file with a UTF-8 byte-order mark (true), as Excel's "CSV UTF-8" format does. Default false.
      Parameters:
      bom - true to write the mark
      Returns:
      these options
    • sheetIndex

      public int sheetIndex()
      The chosen 0-based sheet index, or -1 when the sheet is the default or chosen by sheetName().
    • sheetName

      public String sheetName()
      The sheet name, or null when not chosen by name.
    • delimiter

      public char delimiter()
      The field separator.
    • values

      public CsvOptions.Values values()
      How numeric cells are written.
    • utf8Bom

      public boolean utf8Bom()
      Whether the file starts with a UTF-8 byte-order mark.