Class JxlsWorkbook

java.lang.Object
org.openxava.util.jxls.JxlsWorkbook
All Implemented Interfaces:
JxlsConstants

public class JxlsWorkbook extends Object implements JxlsConstants
JxlsWorkbook: a class to wrap and simplify the use of Apache POI Workbook in the context of OpenXava JxlsWorkbook's can be created: - empty JxlsWorkbook wb = new JxlsWorkbook("Test"); - from a TableModel JxlsWorkbook wb = new JxlsWorkbook(tableModel, "Test"); - from an xls file JxlsWorkbook wb = new JxlsWorkbook(xlsFile); Usage: JxlsWorkbook wb = new JxlsWorkbook("Test"); JxlsSheet sheet = wb.addSheet("Test"); sheet.setValue(3, 4, "Pi", wb.addStyle(TEXT).setAlign(CENTER).setBold()); sheet.setValue(4, 4, 3.141592654, wb.addStyle(FLOAT).setAllBorders(THIN_BORDER)); sheet.setFormula(4, 5, "=2*$R4$C4", wb.addStyle("##0.0000")); sheet.setFormula(4, 6, "=2*R4C4", wb.addStyle("##0.000")); wb.write(new FileOutputStream("c:/Test.xls")); Use of POI more advanced functionalities JxlsWorkbook wb = new JxlsWorkbook("Test"); JxlsSheet sheet = wb.addSheet("Test"); sheet.setValue(3, 4, "Pi", wb.addStyle(TEXT).setAlign(CENTER).setBold()); Workbook poiWorkbook = wb.createPOIWorkbook(); // do an advanced function poiWorkbook.write(new FileOutputStream("c:/Test.xls"));
Author:
Laurent Wibaux
  • Field Details

  • Constructor Details

    • JxlsWorkbook

      public JxlsWorkbook(String name)
      Constructs an empty JxlsWorkbook
      Parameters:
      name - : the name of the JxlsWorkbook
    • JxlsWorkbook

      public JxlsWorkbook(TableModel table, String name)
      Constructs a JxlsWorkbook containing the data of the table
      Parameters:
      table - : a Swing table model
      name - : the name of the Workbook
    • JxlsWorkbook

      public JxlsWorkbook(File xlsFile)
      Constructs a JxlsWorkbook and fills it with the raw data of the input file styles are not copied
      Parameters:
      xlsFile - : an xls file
  • Method Details

    • getFontName

      public String getFontName()
    • setFontName

      public void setFontName(String fontName)
      Sets the default font to use when generating the xls
      Parameters:
      fontName - : the name of the font
    • getFontSize

      public short getFontSize()
    • setFontSize

      public void setFontSize(short fontSize)
      Sets the default font size to use when generating the xls
      Parameters:
      fontSize - : the point size of the font
    • getFloatFormat

      public String getFloatFormat()
    • setFloatFormat

      public void setFloatFormat(String floatFormat)
      Sets the default format to use for numbers when generating the xls This should be in the form "###.0"
      Parameters:
      floatFormat - : the format
    • getIntegerFormat

      public String getIntegerFormat()
    • setIntegerFormat

      public void setIntegerFormat(String integerFormat)
      Sets the default format to use for integers when generating the xls This should be in the form "### ###"
      Parameters:
      integerFormat - : the format
    • getDateFormat

      public String getDateFormat()
    • setDateFormat

      public void setDateFormat(String dateFormat)
      Sets the default format to use for integers when generating the xls This should be in the form "dd/MM/yy"
      Parameters:
      dateFormat - : the format
    • getDefaultStyle

      public JxlsStyle getDefaultStyle()
    • getDefaultDateStyle

      public JxlsStyle getDefaultDateStyle()
    • getDefaultFloatStyle

      public JxlsStyle getDefaultFloatStyle()
    • addStyle

      public JxlsStyle addStyle(int type)
    • addStyle

      public JxlsStyle addStyle(String format)
    • addClonedStyle

      public JxlsStyle addClonedStyle(JxlsStyle style)
    • addStyle

      public JxlsStyle addStyle(String name, int type)
      Creates a JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)
      Parameters:
      name - the name to use when recalling the style
      type - the type of value managed by the style (one of: TEXT, INTEGER, FLOAT, DATE)
      Returns:
      the JxlsStyle
    • addStyle

      public JxlsStyle addStyle(String name, String format)
      Creates a JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)
      Parameters:
      name - the name to use when recalling the style
      format - the format the style should use ("#.0%")
      Returns:
      the JxlsStyle
    • addClonedStyle

      public JxlsStyle addClonedStyle(String name, JxlsStyle style)
      Creates a JxlsStyle based upon another existing JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)
      Parameters:
      name - the name to use when recalling the style
      style - the style to clone
      Returns:
      the cloned JxlsStyle
    • getStyle

      public JxlsStyle getStyle(String name)
    • addSheet

      public JxlsSheet addSheet(String name)
      Creates a JxlsSheet in which cells can be added
      Parameters:
      name - the name which will appear on the tab
      Returns:
      the JxlsSheet
    • addSheet

      public JxlsSheet addSheet(String name, int index)
      Creates a JxlsSheet in which cells can be added
      Parameters:
      name - the name which will appear on the tab
      index - the index at which the sheet should appear in the tab list
      Returns:
      the JxlsSheet
    • deleteSheet

      public void deleteSheet(int index)
      Deletes a JxlsSheet
      Parameters:
      index - the index of the tab to delete
    • getSheet

      public JxlsSheet getSheet(int index)
      Gets a sheet through its index
      Parameters:
      index - the index of the sheet
      Returns:
      the JxlsSheet
    • getSheet

      public JxlsSheet getSheet(String name)
      Gets a sheet through its name
      Parameters:
      name - the name of the sheet
      Returns:
      the JxlsSheet
    • getSheets

      public Vector<JxlsSheet> getSheets()
      Gets the list of sheets
      Returns:
      a Vector
    • getSheetsMap

      public Map<String,JxlsSheet> getSheetsMap()
      Gets a map containing the sheets mapped by name
      Returns:
      a Map<String, JxlsSheet>
    • deletePOIWorkbook

      public void deletePOIWorkbook()
      Resets the Apache POI Workbook from the JxlsWorkbok to regenerate the Workbook on next createPOIWorkbook
    • createPOIWorkbook

      public org.apache.poi.ss.usermodel.Workbook createPOIWorkbook()
      Creates an apache POI Workbook from the JxlsWorkbok
      Returns:
      a Workbook
    • write

      public void write(OutputStream os) throws Exception
      Writes the xls to an OutputStream
      Parameters:
      os - the OutputStream to write to
      Throws:
      Exception - if the OutputStream can not be opened
    • write

      public void write(javax.servlet.http.HttpServletResponse response) throws Exception
      Writes the xls to an HttpServletResponse, setting the correct mime type and headers
      Parameters:
      response - the HttpServletResponse to write to
      Throws:
      Exception - if the HttpServletResponse can not be written
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception