[]
        
(Showing Draft Content)

ITableDataSource

Interface ITableDataSource


public interface ITableDataSource
Represents a custom table data source.

Classes that implement this interface can be used as a ResultSet -like data source for template processing. An ITableDataSource exposes tabular data through row and column indexes, together with column metadata, so that it can be added to a workbook by using Workbook.addDataSource(String,Object).


 class ExampleTableDataSource implements ITableDataSource {
     private final Object[][] data = {
         { "Alice" },
         { "Bob" }
     };

     private final String[] columns = { "Customer" };

     public Object getValue(int row, int column) {
         return data[row][column];
     }

     public int getRowCount() {
         return data.length;
     }

     public int getColumnCount() {
         return columns.length;
     }

     public String getColumnName(int column) {
         return columns[column];
     }

     public int getColumnIndex(String columnName) {
         return java.util.Arrays.asList(columns).indexOf(columnName);
     }
 }

 ITableDataSource dataSource = new ExampleTableDataSource();
 workbook.addDataSource("customers", dataSource);
 
  • Method Details

    • getValue

      Object getValue(int row, int column)
      Gets a value from the data source.
      
       ITableDataSource dataSource = new ExampleTableDataSource();
       Object value = dataSource.getValue(0, 0);
       
      Parameters:
      row - start from 0
      column - start from 0
      Returns:
      value
    • getRowCount

      int getRowCount()
      Gets the row count.
      
       ITableDataSource dataSource = new ExampleTableDataSource();
       int rowCount = dataSource.getRowCount();
       
      Returns:
      row count
    • getColumnCount

      int getColumnCount()
      Gets the column count.
      
       ITableDataSource dataSource = new ExampleTableDataSource();
       int columnCount = dataSource.getColumnCount();
       
      Returns:
      column count
    • getColumnName

      String getColumnName(int column)
      Gets the column name.
      
       ITableDataSource dataSource = new ExampleTableDataSource();
       String columnName = dataSource.getColumnName(0);
       
      Parameters:
      column - start from 0
      Returns:
      column name
    • getColumnIndex

      int getColumnIndex(String columnName)
      Gets the column index.
      
       ITableDataSource dataSource = new ExampleTableDataSource();
       int columnIndex = dataSource.getColumnIndex("Customer");
       
      Parameters:
      columnName - The column name.
      Returns:
      The column index.