Class StreamRow

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

public final class StreamRow extends Object
A row under construction for StreamWorkbook.

Obtained from StreamWorkbook.row(int), filled with set* / add* calls, and committed with commit(). The same instance is handed back for every row of a workbook and its buffers are reused, so writing ten million rows allocates the buffers once. That reuse keeps the Java side's memory as flat as the engine's.

Cells may be set in any column order; only the columns actually set are written. Columns are 0-based (0 is column A) and the last column is 16383 (XFD); a column past it makes commit() throw AxyraIoException. Setting the same column twice keeps the last value. The add* methods write at the column after the last one set, starting at column 0.

A style argument is an index returned by StreamWorkbook.addStyle(io.keikai.axyra.sheets.io.StreamStyle); 0 is the default style. The index is not checked: an index that addStyle did not return writes an invalid style reference into the file. Overloads without style use 0. A negative column throws IllegalArgumentException.


 try (StreamWorkbook wb = StreamWorkbook.create(path)) {
     int bold = wb.addStyle(StreamStyle.defaults().withBold());
     wb.startSheet("Report");
     wb.row(0).addText("Id", bold).addText("Name", bold).commit();
     for (int r = 1; r <= 1_000_000; r++) {
         wb.row(r).addNumber(r).addText("Customer " + r).commit();
     }
 }
 
  • Method Details

    • addNumber

      public StreamRow addNumber(double value)
      Appends a number at the next column; same as setNumber(next, value).
    • addNumber

      public StreamRow addNumber(double value, int style)
      Appends a number with a style index at the next column.
    • addText

      public StreamRow addText(String value)
      Appends text at the next column; null writes a blank.
    • addText

      public StreamRow addText(String value, int style)
      Appends text with a style index at the next column; null writes a styled blank.
    • addBoolean

      public StreamRow addBoolean(boolean value)
      Appends a boolean at the next column.
    • addDate

      public StreamRow addDate(LocalDate value, int style)
      Appends a date at the next column; style must carry a date format. See setDate(int, LocalDate, int) for the serial rules.
    • skip

      public StreamRow skip()
      Leaves the next column empty and moves past it; nothing is written for it.
    • setNumber

      public StreamRow setNumber(int column, double value)
      Sets a number at 0-based column with the default style; see setNumber(int, double, int).
    • setNumber

      public StreamRow setNumber(int column, double value, int style)
      Sets a number at 0-based column (0-16383) with a style index from StreamWorkbook.addStyle(io.keikai.axyra.sheets.io.StreamStyle). NaN and infinity are written as 0.
      Parameters:
      column - the 0-based column
      value - the number
      style - the style index; 0 is the default style
      Returns:
      this row
      Throws:
      IllegalArgumentException - if column is negative
    • setText

      public StreamRow setText(int column, String value)
      Sets text at 0-based column. A null value writes nothing visible: an unstyled blank.
    • setText

      public StreamRow setText(int column, String value, int style)
      Sets text at 0-based column with a style index. The text is stored inline in the cell, not in a shared string table.
      Parameters:
      column - the 0-based column
      value - the text; null writes a blank with style
      style - the style index; 0 is the default style
      Returns:
      this row
      Throws:
      IllegalArgumentException - if column is negative
    • setBoolean

      public StreamRow setBoolean(int column, boolean value)
      Sets TRUE or FALSE at 0-based column with the default style.
    • setBoolean

      public StreamRow setBoolean(int column, boolean value, int style)
      Sets TRUE or FALSE at 0-based column with a style index.
    • setFormula

      public StreamRow setFormula(int column, String formula)
      Sets a formula at 0-based column, e.g. "SUM(A1:A9)". A leading = is accepted and removed. The formula is written as given and not checked.

      No cached result is written, so Excel shows 0 until it recalculates. Use setFormula(int, String, double, int) when the value is known, as it usually is for a report generator.

      Parameters:
      column - the 0-based column
      formula - the formula in en-US syntax
      Returns:
      this row
      Throws:
      IllegalArgumentException - if formula is null or empty, or column is negative
    • setFormula

      public StreamRow setFormula(int column, String formula, int style)
      Sets a formula at 0-based column with a style index, without a cached result. A leading = is accepted and removed.
      Parameters:
      column - the 0-based column
      formula - the formula in en-US syntax
      style - the style index; 0 is the default style
      Returns:
      this row
      Throws:
      IllegalArgumentException - if formula is null or empty, or column is negative
    • setFormula

      public StreamRow setFormula(int column, String formula, double cachedValue, int style)
      Sets a formula plus the cached numeric result that readers show before they recalculate. A leading = is accepted and removed.
      Parameters:
      column - the 0-based column
      formula - the formula in en-US syntax
      cachedValue - the result to store; NaN and infinity are written as 0
      style - the style index; 0 is the default style
      Returns:
      this row
      Throws:
      IllegalArgumentException - if formula is null or empty, or column is negative
    • setBlank

      public StreamRow setBlank(int column, int style)
      Sets a blank at 0-based column that carries a style index. A blank with style 0 is not written at all.
    • setDate

      public StreamRow setDate(int column, LocalDate value, int style)
      Sets a date at 0-based column. Excel has no date type: the cell holds a serial number and style must carry a date number format, e.g. StreamStyle.defaults().withNumberFormat("yyyy-mm-dd").

      The serial counts days from 1899-12-30 (the 1900 date system). Excel counts a 29 February 1900 that did not exist, so a date before 1900-03-01 shows one day later in Excel.

      Parameters:
      column - the 0-based column
      value - the date; null writes a blank with style
      style - a style index whose number format is a date format
      Returns:
      this row
      Throws:
      IllegalArgumentException - if column is negative
    • setDateTime

      public StreamRow setDateTime(int column, LocalDateTime value, int style)
      Sets a date-time at 0-based column; the time of day becomes the fractional part of the serial. The date rules of setDate(int, LocalDate, int) apply.
      Parameters:
      column - the 0-based column
      value - the date-time; null writes a blank with style
      style - a style index whose number format shows a date or time
      Returns:
      this row
      Throws:
      IllegalArgumentException - if column is negative
    • commit

      public void commit()
      Writes the row to the file. Call StreamWorkbook.row(int) for the next row; committing the same row twice throws.
      Throws:
      AxyraIoException - if the row index is not above the previous committed row, is 1,048,576 or above, a column is past 16383, or the file cannot be written
      IllegalStateException - if the writer is closed