Class ExcelBuilder

  • All Implemented Interfaces:
    IExcelBuilder
    Direct Known Subclasses:
    ExcelBuilderMultiSheet

    public class ExcelBuilder
    extends Object
    implements IExcelBuilder
    A utility wrapper around Apache POI Excel spreadsheet builder. Comments only supported on XLS type (no XLSX) To add new excel features, see
    • Field Detail

      • MAX_COLUMN

        public static int MAX_COLUMN
        The max number of columns supported by an excel sheet (256="IV" column header)
      • MAX_ROW

        public static int MAX_ROW
        The max number of rows supported by an excel sheet
      • LAST_COLUMN

        public static int LAST_COLUMN
      • LAST_ROW

        public static int LAST_ROW
      • CRASH_ON_CELL_OVERFLOW

        public static boolean CRASH_ON_CELL_OVERFLOW
        States if the builder should throw an IllegalArgumentException or simply warn with a log once a cell index exceed max number of columns or row.
      • workbook

        protected org.apache.poi.ss.usermodel.Workbook workbook
      • create

        protected org.apache.poi.ss.usermodel.CreationHelper create
      • drawing

        protected org.apache.poi.ss.usermodel.Drawing drawing
      • boldFont

        protected org.apache.poi.ss.usermodel.Font boldFont
      • currentSheetId

        protected int currentSheetId
      • sheets

        protected Map<Integer,​org.apache.poi.ss.usermodel.Sheet> sheets
    • Constructor Detail

      • ExcelBuilder

        public ExcelBuilder()
      • ExcelBuilder

        public ExcelBuilder​(ExcelBuilder.Type type,
                            String firstSheetName,
                            org.apache.poi.ss.usermodel.Workbook workbook)
      • ExcelBuilder

        public ExcelBuilder​(org.apache.poi.ss.usermodel.Workbook workbook)
    • Method Detail

      • getWorkbook

        public org.apache.poi.ss.usermodel.Workbook getWorkbook()
        Specified by:
        getWorkbook in interface IExcelBuilder
      • getHSSFWorkbook

        public org.apache.poi.hssf.usermodel.HSSFWorkbook getHSSFWorkbook()
      • getXSSFWorkbook

        public org.apache.poi.xssf.usermodel.XSSFWorkbook getXSSFWorkbook()
      • setCell

        public org.apache.poi.ss.usermodel.Cell setCell​(int row,
                                                        int column,
                                                        String content,
                                                        org.apache.poi.ss.usermodel.CellStyle style)
        Set a cell content at the given indices, and apply the style if it is not null. If row(i) does not exist yet, it is created, otherwise it is recycled. If cell(i,j) does not exist yet, it is created, otherwise it is recycled. Reminder: excel support a maximum of 65,536 rows and 256 columns per sheet
        Specified by:
        setCell in interface IExcelBuilder
        Parameters:
        row - row index
        column - column index
        content - a string to display in the cell
        style - a style to apply to the cell
        Returns:
        the created or retrieved cell in case additional stuff should be done on it.
      • validateCellIndex

        protected boolean validateCellIndex​(int row,
                                            int column,
                                            String content)
        Validate a cell index. If cell index is out of maximum number of rows/columns:
      • setCell

        public org.apache.poi.ss.usermodel.Cell setCell​(int row,
                                                        int column,
                                                        String content)
        Set a cell text content with no styling information.
        Specified by:
        setCell in interface IExcelBuilder
      • setCellFormula

        public org.apache.poi.ss.usermodel.Cell setCellFormula​(int row,
                                                               int column,
                                                               String formula)
        Specified by:
        setCellFormula in interface IExcelBuilder
      • setCell

        public org.apache.poi.ss.usermodel.Cell setCell​(int row,
                                                        int column,
                                                        double value)
        Specified by:
        setCell in interface IExcelBuilder
      • setCell

        public org.apache.poi.ss.usermodel.Cell setCell​(int row,
                                                        int column,
                                                        double value,
                                                        org.apache.poi.ss.usermodel.CellStyle style)
        Specified by:
        setCell in interface IExcelBuilder
      • setHyperlink

        public void setHyperlink​(org.apache.poi.ss.usermodel.Cell cell,
                                 String link)
      • getSheet

        public org.apache.poi.ss.usermodel.Sheet getSheet​(String name)
      • setCurrentSheet

        public org.apache.poi.ss.usermodel.Sheet setCurrentSheet​(String name)
      • setCurrentSheet

        public void setCurrentSheet​(org.apache.poi.ss.usermodel.Sheet s)
        Set current Sheet in which cell are set. Different from setActiveSheet(int).
      • setSheetOrder

        public void setSheetOrder​(String name,
                                  int order)
      • newSheet

        public org.apache.poi.ss.usermodel.Sheet newSheet​(String name)
      • getAllSheetNames

        public List<String> getAllSheetNames()
      • sheetInitialized

        protected boolean sheetInitialized​(int index)
      • setColumnWidth

        public void setColumnWidth​(int column,
                                   int width)
        Set the width (in units of 1/256th of a character width)
        Specified by:
        setColumnWidth in interface IExcelBuilder
      • setFreezePane

        public void setFreezePane​(int colSplit,
                                  int rowSplit)
        Specified by:
        setFreezePane in interface IExcelBuilder
      • setFreezePane

        public void setFreezePane​(int colSplit,
                                  int rowSplit,
                                  int leftmostColumn,
                                  int topRow)
        Specified by:
        setFreezePane in interface IExcelBuilder
      • setSplitPane

        public void setSplitPane​(int xSplitPos,
                                 int ySplitPos,
                                 int leftmostColumn,
                                 int topRow,
                                 int activePane)
        Specified by:
        setSplitPane in interface IExcelBuilder
      • mergeRange

        public void mergeRange​(int firstRow,
                               int firstColumn,
                               int lastRow,
                               int lastColumn)
        Specified by:
        mergeRange in interface IExcelBuilder
      • getOrCreateCell

        public org.apache.poi.ss.usermodel.Cell getOrCreateCell​(int i,
                                                                int j)
      • getCell

        public org.apache.poi.ss.usermodel.Cell getCell​(int i,
                                                        int j)
      • getOrCreateRow

        protected org.apache.poi.ss.usermodel.Row getOrCreateRow​(int i)
      • addComment

        public org.apache.poi.ss.usermodel.Comment addComment​(org.apache.poi.ss.usermodel.Cell cell,
                                                              String text,
                                                              int row,
                                                              int col,
                                                              int colWidth,
                                                              int rowHeight)
        Specified by:
        addComment in interface IExcelBuilder
      • buildComment

        public org.apache.poi.ss.usermodel.Comment buildComment​(String text,
                                                                int row,
                                                                int col,
                                                                int colWidth,
                                                                int rowHeight)
        Return a Comment. Comments are supported only on XLS file (HSSF framework).
        Parameters:
        row -
        col -
        colWidth -
        rowHeight -
        Returns:
      • newColoredCellStyle

        public org.apache.poi.ss.usermodel.CellStyle newColoredCellStyle​(org.apache.poi.ss.usermodel.IndexedColors color)
        Specified by:
        newColoredCellStyle in interface IExcelBuilder
      • getColor

        public org.apache.poi.hssf.util.HSSFColor getColor​(byte r,
                                                           byte g,
                                                           byte b)
      • setPicture

        public void setPicture​(int pictureIdx,
                               int col1,
                               int row1,
                               boolean resize)
        Specified by:
        setPicture in interface IExcelBuilder
      • getBoldFont

        public org.apache.poi.ss.usermodel.Font getBoldFont()
        Specified by:
        getBoldFont in interface IExcelBuilder
      • newFont

        public org.apache.poi.ss.usermodel.Font newFont​(int size)
        Specified by:
        newFont in interface IExcelBuilder
      • getCreationHelper

        public org.apache.poi.ss.usermodel.CreationHelper getCreationHelper()