Class ExcelPrintSetup

java.lang.Object
io.github.dornol.excelkit.excel.ExcelPrintSetup

public class ExcelPrintSetup extends Object
Configures page layout settings for printing Excel sheets.

Supports orientation, paper size, margins, headers/footers, repeat rows, and fit-to-page scaling. Use with ExcelWriter.printSetup(java.util.function.Consumer) or ExcelSheetWriter.printSetup(java.util.function.Consumer).

  • &P — current page number
  • &N — total number of pages
  • &D — current date
  • &T — current time
  • &F — file name
  • Constructor Details

    • ExcelPrintSetup

      public ExcelPrintSetup()
      Creates a new print setup configuration with defaults.
  • Method Details

    • orientation

      public ExcelPrintSetup orientation(ExcelPrintSetup.Orientation orientation)
      Sets the page orientation.
      Parameters:
      orientation - the page orientation
      Returns:
      this instance for chaining
    • paperSize

      public ExcelPrintSetup paperSize(ExcelPrintSetup.PaperSize paperSize)
      Sets the paper size.
      Parameters:
      paperSize - the paper size
      Returns:
      this instance for chaining
    • margins

      public ExcelPrintSetup margins(double left, double right, double top, double bottom)
      Sets all four page margins at once.
      Parameters:
      left - left margin in inches
      right - right margin in inches
      top - top margin in inches
      bottom - bottom margin in inches
      Returns:
      this instance for chaining
    • leftMargin

      public ExcelPrintSetup leftMargin(double inches)
      Sets the left margin.
      Parameters:
      inches - margin in inches
      Returns:
      this instance for chaining
    • rightMargin

      public ExcelPrintSetup rightMargin(double inches)
      Sets the right margin.
      Parameters:
      inches - margin in inches
      Returns:
      this instance for chaining
    • topMargin

      public ExcelPrintSetup topMargin(double inches)
      Sets the top margin.
      Parameters:
      inches - margin in inches
      Returns:
      this instance for chaining
    • bottomMargin

      public ExcelPrintSetup bottomMargin(double inches)
      Sets the bottom margin.
      Parameters:
      inches - margin in inches
      Returns:
      this instance for chaining
    • headerLeft

      public ExcelPrintSetup headerLeft(String text)
      Sets the left section of the page header.

      Supports special codes: &P (page number), &N (total pages), &D (date), &T (time), &F (filename).

      Parameters:
      text - header text
      Returns:
      this instance for chaining
    • headerCenter

      public ExcelPrintSetup headerCenter(String text)
      Sets the center section of the page header.
      Parameters:
      text - header text
      Returns:
      this instance for chaining
      See Also:
    • headerRight

      public ExcelPrintSetup headerRight(String text)
      Sets the right section of the page header.
      Parameters:
      text - header text
      Returns:
      this instance for chaining
      See Also:
    • footerLeft

      public ExcelPrintSetup footerLeft(String text)
      Sets the left section of the page footer.
      Parameters:
      text - footer text
      Returns:
      this instance for chaining
      See Also:
    • footerCenter

      public ExcelPrintSetup footerCenter(String text)
      Sets the center section of the page footer.
      Parameters:
      text - footer text
      Returns:
      this instance for chaining
      See Also:
    • footerRight

      public ExcelPrintSetup footerRight(String text)
      Sets the right section of the page footer.
      Parameters:
      text - footer text
      Returns:
      this instance for chaining
      See Also:
    • repeatHeaderRows

      public ExcelPrintSetup repeatHeaderRows()
      Repeats header rows (from row 0 through the column header row) on every printed page.

      This includes any rows added by beforeHeader and group header rows.

      Returns:
      this instance for chaining
    • repeatRows

      public ExcelPrintSetup repeatRows(int firstRow, int lastRow)
      Repeats specific rows on every printed page.
      Parameters:
      firstRow - first row to repeat (0-based)
      lastRow - last row to repeat (0-based, inclusive)
      Returns:
      this instance for chaining
    • fitToPage

      public ExcelPrintSetup fitToPage(int width, int height)
      Enables fit-to-page scaling with the specified width and height in pages.

      Use height = 0 for automatic height scaling.

      Parameters:
      width - number of pages wide
      height - number of pages tall (0 for auto)
      Returns:
      this instance for chaining
    • fitToPageWidth

      public ExcelPrintSetup fitToPageWidth()
      Fits the sheet to one page wide with automatic height.
      Returns:
      this instance for chaining