Class GridExporter<T>

java.lang.Object
com.flowingcode.vaadin.addons.gridexporter.GridExporter<T>
All Implemented Interfaces:
Serializable

public class GridExporter<T> extends Object implements Serializable
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> GridExporter<T>
    createFor(com.vaadin.flow.component.grid.Grid<T> grid)
     
    static <T> GridExporter<T>
    createFor(com.vaadin.flow.component.grid.Grid<T> grid, String excelCustomTemplate, String docxCustomTemplate)
     
     
    List<com.vaadin.flow.component.grid.Grid.Column<T>>
     
    List<com.vaadin.flow.component.grid.Grid.Column<T>>
    Get columns in the positions specified by GridExporter.setColumnPosition
    Charset to use when exporting the CSV file.
    com.vaadin.flow.server.StreamResource
     
    com.vaadin.flow.server.StreamResource
     
    com.vaadin.flow.server.StreamResource
     
    com.vaadin.flow.server.StreamResource
     
    com.vaadin.flow.server.StreamResource
     
     
    com.vaadin.flow.server.StreamResource
     
    com.vaadin.flow.server.StreamResource
     
    int
     
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    void
    setAdditionalPlaceHolders(Map<String,String> additionalPlaceHolders)
    Sets a map that will contain additional place holders that will be replaced with values when processing the exported file
    void
    setAutoAttachExportButtons(boolean autoAttachExportButtons)
    If true, it will automatically generate export buttons in the asociated grid
    void
    setAutoMergeTitle(boolean autoMergeTitle)
    If true the title cell will be merged with the next ones to create a single title cell that will span across the columns
    void
    setAutoSizeColumns(boolean autoSizeColumns)
     
    void
     
    void
    setColumnPosition(com.vaadin.flow.component.grid.Grid.Column<T> column, int position)
    Assigns the position of the column in the exported file.
    void
    setColumns(List<com.vaadin.flow.component.grid.Grid.Column<T>> columns)
     
    void
    setCsvCharset(com.vaadin.flow.function.SerializableSupplier<Charset> charset)
     
    void
    setCsvExportEnabled(boolean csvExportEnabled)
     
    void
    setCustomFooter(com.vaadin.flow.component.grid.Grid.Column<T> column, String header)
    Configures the exporter to use a custom string for a specific column's footer.
    void
    setCustomHeader(com.vaadin.flow.component.grid.Grid.Column<T> column, String header)
    Configures the exporter to use a custom string for a specific column's header.
    void
    setDateColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, String excelFormat)
    If the column is based on a LocalDate attribute of the item, rendered with a LocalDateRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.
    void
    setDateColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, DateFormat dateFormat, String excelFormat)
    If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.
    void
    setDateColumnFormatProvider(com.vaadin.flow.component.grid.Grid.Column<T> column, DateFormat dateFormat, com.vaadin.flow.function.ValueProvider<T,String> excelFormatProvider)
    If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.
    void
    setDocxExportEnabled(boolean docxExportEnabled)
     
    void
    setExcelExportEnabled(boolean excelExportEnabled)
     
    void
    setExportColumn(com.vaadin.flow.component.grid.Grid.Column<T> column, boolean export)
    Configure if the column is exported or not
    void
    setExportValue(com.vaadin.flow.component.grid.Grid.Column<T> column, com.vaadin.flow.function.ValueProvider<T,?> vp)
    Configure a value provider for a given column.
    void
    setFileName(String fileName)
    Sets the filename of the exported file
    void
     
    void
    setNullValueHandler(com.vaadin.flow.function.SerializableSupplier<String> nullValueSupplier)
     
    void
    setNumberColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, String excelFormat)
    If the column is based on a number attribute of the item, rendered with a NumberRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.
    void
    setNumberColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, DecimalFormat decimalFormat, String excelFormat)
    If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.
    void
    setNumberColumnFormatProvider(com.vaadin.flow.component.grid.Grid.Column<T> column, DecimalFormat decimalFormat, com.vaadin.flow.function.ValueProvider<T,String> excelFormatProvider)
    If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel with a provider, so the resulting cell is not a string but a number that can be used in formulas.
    void
    setPdfExportEnabled(boolean pdfExportEnabled)
     
    void
    setSheetNumber(int sheetNumber)
    Configures the excel sheet that will be inspected for placeholders to export the data
    void
    Sets the title of the exported file

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • totalcells

      public int totalcells
  • Method Details

    • createFor

      public static <T> GridExporter<T> createFor(com.vaadin.flow.component.grid.Grid<T> grid)
    • createFor

      public static <T> GridExporter<T> createFor(com.vaadin.flow.component.grid.Grid<T> grid, String excelCustomTemplate, String docxCustomTemplate)
    • setButtonsAlignment

      public void setButtonsAlignment(ButtonsAlignment buttonsAlignment)
    • getDocxStreamResource

      public com.vaadin.flow.server.StreamResource getDocxStreamResource()
    • getDocxStreamResource

      public com.vaadin.flow.server.StreamResource getDocxStreamResource(String template)
    • getPdfStreamResource

      public com.vaadin.flow.server.StreamResource getPdfStreamResource()
    • getPdfStreamResource

      public com.vaadin.flow.server.StreamResource getPdfStreamResource(String template)
    • getCsvStreamResource

      public com.vaadin.flow.server.StreamResource getCsvStreamResource()
    • getExcelStreamResource

      public com.vaadin.flow.server.StreamResource getExcelStreamResource()
    • getExcelStreamResource

      public com.vaadin.flow.server.StreamResource getExcelStreamResource(String template)
    • getTitle

      public String getTitle()
    • setTitle

      public void setTitle(String title)
      Sets the title of the exported file
      Parameters:
      title -
    • getFileName

      public String getFileName()
    • setFileName

      public void setFileName(String fileName)
      Sets the filename of the exported file
      Parameters:
      fileName -
    • isAutoAttachExportButtons

      public boolean isAutoAttachExportButtons()
    • setAutoAttachExportButtons

      public void setAutoAttachExportButtons(boolean autoAttachExportButtons)
      If true, it will automatically generate export buttons in the asociated grid
      Parameters:
      autoAttachExportButtons -
    • getAdditionalPlaceHolders

      public Map<String,String> getAdditionalPlaceHolders()
    • setAdditionalPlaceHolders

      public void setAdditionalPlaceHolders(Map<String,String> additionalPlaceHolders)
      Sets a map that will contain additional place holders that will be replaced with values when processing the exported file
      Parameters:
      additionalPlaceHolders -
    • getSheetNumber

      public int getSheetNumber()
    • setSheetNumber

      public void setSheetNumber(int sheetNumber)
      Configures the excel sheet that will be inspected for placeholders to export the data
      Parameters:
      sheetNumber -
    • isAutoMergeTitle

      public boolean isAutoMergeTitle()
    • setAutoMergeTitle

      public void setAutoMergeTitle(boolean autoMergeTitle)
      If true the title cell will be merged with the next ones to create a single title cell that will span across the columns
      Parameters:
      autoMergeTitle -
    • isExcelExportEnabled

      public boolean isExcelExportEnabled()
    • setExcelExportEnabled

      public void setExcelExportEnabled(boolean excelExportEnabled)
    • isDocxExportEnabled

      public boolean isDocxExportEnabled()
    • setDocxExportEnabled

      public void setDocxExportEnabled(boolean docxExportEnabled)
    • isPdfExportEnabled

      public boolean isPdfExportEnabled()
    • setPdfExportEnabled

      public void setPdfExportEnabled(boolean pdfExportEnabled)
    • isCsvExportEnabled

      public boolean isCsvExportEnabled()
    • setCsvExportEnabled

      public void setCsvExportEnabled(boolean csvExportEnabled)
    • isAutoSizeColumns

      public boolean isAutoSizeColumns()
    • setAutoSizeColumns

      public void setAutoSizeColumns(boolean autoSizeColumns)
    • setExportValue

      public void setExportValue(com.vaadin.flow.component.grid.Grid.Column<T> column, com.vaadin.flow.function.ValueProvider<T,?> vp)
      Configure a value provider for a given column. If there is a value provider, that will be taken into account when exporting the column
      Parameters:
      column -
      vp -
    • setExportColumn

      public void setExportColumn(com.vaadin.flow.component.grid.Grid.Column<T> column, boolean export)
      Configure if the column is exported or not
      Parameters:
      column -
      export - : true will be included in the exported file, false will not be included
    • setNullValueHandler

      public void setNullValueHandler(com.vaadin.flow.function.SerializableSupplier<String> nullValueSupplier)
    • setNumberColumnFormat

      public void setNumberColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, DecimalFormat decimalFormat, String excelFormat)
      If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.
      Parameters:
      column -
      decimalFormat -
      excelFormat -
    • setNumberColumnFormatProvider

      public void setNumberColumnFormatProvider(com.vaadin.flow.component.grid.Grid.Column<T> column, DecimalFormat decimalFormat, com.vaadin.flow.function.ValueProvider<T,String> excelFormatProvider)
      If the column is based on a String, it configures a DecimalFormat to parse a number from the value of the column so it can be converted to a Double, and then allows to specify the excel format to be applied to the cell when exported to excel with a provider, so the resulting cell is not a string but a number that can be used in formulas.
      Parameters:
      column -
      decimalFormat -
      excelFormatProvider -
    • setDateColumnFormat

      public void setDateColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, DateFormat dateFormat, String excelFormat)
      If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.
      Parameters:
      column -
      dateFormat -
      excelFormat -
    • setDateColumnFormatProvider

      public void setDateColumnFormatProvider(com.vaadin.flow.component.grid.Grid.Column<T> column, DateFormat dateFormat, com.vaadin.flow.function.ValueProvider<T,String> excelFormatProvider)
      If the column is based on a String, it configures a DateFormat to parse a date from the value of the column so it can be converted to a java.util.Date, and then allows to specify the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.
      Parameters:
      column -
      dateFormat -
      excelFormat -
    • setNumberColumnFormat

      public void setNumberColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, String excelFormat)
      If the column is based on a number attribute of the item, rendered with a NumberRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a number that can be used in formulas.
      Parameters:
      column -
      excelFormat -
    • setDateColumnFormat

      public void setDateColumnFormat(com.vaadin.flow.component.grid.Grid.Column<T> column, String excelFormat)
      If the column is based on a LocalDate attribute of the item, rendered with a LocalDateRenderer, it configures the excel format to be applied to the cell when exported to excel, so the resulting cell is not a string but a date that can be used in formulas.
      Parameters:
      column -
      excelFormat -
    • setCustomHeader

      public void setCustomHeader(com.vaadin.flow.component.grid.Grid.Column<T> column, String header)
      Configures the exporter to use a custom string for a specific column's header. Usefull when the header is a custom component.
      Parameters:
      column -
      header -
    • setCustomFooter

      public void setCustomFooter(com.vaadin.flow.component.grid.Grid.Column<T> column, String header)
      Configures the exporter to use a custom string for a specific column's footer. Usefull when the footer is a custom component.
      Parameters:
      column -
      header -
    • setColumnPosition

      public void setColumnPosition(com.vaadin.flow.component.grid.Grid.Column<T> column, int position)
      Assigns the position of the column in the exported file.
      Parameters:
      column -
      position -
    • setColumns

      public void setColumns(List<com.vaadin.flow.component.grid.Grid.Column<T>> columns)
    • getColumns

      public List<com.vaadin.flow.component.grid.Grid.Column<T>> getColumns()
    • getColumnsOrdered

      public List<com.vaadin.flow.component.grid.Grid.Column<T>> getColumnsOrdered()
      Get columns in the positions specified by GridExporter.setColumnPosition
      Returns:
    • setFooterToolbarItems

      public void setFooterToolbarItems(List<FooterToolbarItem> footerToolbarItems)
    • getCsvCharset

      public Charset getCsvCharset()
      Charset to use when exporting the CSV file.
      Returns:
      CSV file charset or default one.
    • setCsvCharset

      public void setCsvCharset(com.vaadin.flow.function.SerializableSupplier<Charset> charset)