Package org.openxava.util.jxls
Class JxlsWorkbook
- java.lang.Object
-
- org.openxava.util.jxls.JxlsWorkbook
-
- All Implemented Interfaces:
JxlsConstants
public class JxlsWorkbook extends java.lang.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 functionalitiesJxlsWorkbook 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 Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,org.apache.poi.ss.usermodel.Font>
fonts
protected org.apache.poi.ss.usermodel.Workbook
poiWorkbook
protected java.util.Map<java.lang.String,JxlsSheet>
sheetNames
protected java.util.Vector<JxlsSheet>
sheets
protected java.util.Map<java.lang.String,JxlsStyle>
styles
-
Fields inherited from interface org.openxava.util.jxls.JxlsConstants
ALL, AUTO_SIZE, BLACK, BLUE, BOLD, BORDER_NONE, BORDER_THICK, BORDER_THIN, BOTTOM, CENTER, DATE, EMPTY, FLOAT, GREEN, INTEGER, LEFT, LEFT_RIGHT, LIGHT_GREEN, LIGHT_GREY, LIGHT_YELLOW, NONE, PLAIN, RED, RIGHT, TEXT, TOP, TOP_BOTTOM, WHITE
-
-
Constructor Summary
Constructors Constructor Description JxlsWorkbook(java.io.File xlsFile)
Constructs a JxlsWorkbook and fills it with the raw data of the input file styles are not copiedJxlsWorkbook(java.lang.String name)
Constructs an empty JxlsWorkbookJxlsWorkbook(javax.swing.table.TableModel table, java.lang.String name)
Constructs a JxlsWorkbook containing the data of the table
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JxlsStyle
addClonedStyle(java.lang.String name, JxlsStyle style)
Creates a JxlsStyle based upon another existing JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)JxlsStyle
addClonedStyle(JxlsStyle style)
JxlsSheet
addSheet(java.lang.String name)
Creates a JxlsSheet in which cells can be addedJxlsSheet
addSheet(java.lang.String name, int index)
Creates a JxlsSheet in which cells can be addedJxlsStyle
addStyle(int type)
JxlsStyle
addStyle(java.lang.String format)
JxlsStyle
addStyle(java.lang.String name, int type)
Creates a JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)JxlsStyle
addStyle(java.lang.String name, java.lang.String format)
Creates a JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)org.apache.poi.ss.usermodel.Workbook
createPOIWorkbook()
Creates an apache POI Workbook from the JxlsWorkbokvoid
deletePOIWorkbook()
Resets the Apache POI Workbook from the JxlsWorkbok to regenerate the Workbook on next createPOIWorkbookvoid
deleteSheet(int index)
Deletes a JxlsSheetjava.lang.String
getDateFormat()
JxlsStyle
getDefaultDateStyle()
JxlsStyle
getDefaultFloatStyle()
JxlsStyle
getDefaultStyle()
java.lang.String
getFloatFormat()
java.lang.String
getFontName()
short
getFontSize()
java.lang.String
getIntegerFormat()
JxlsSheet
getSheet(int index)
Gets a sheet through its indexJxlsSheet
getSheet(java.lang.String name)
Gets a sheet through its namejava.util.Vector<JxlsSheet>
getSheets()
Gets the list of sheetsjava.util.Map<java.lang.String,JxlsSheet>
getSheetsMap()
Gets a map containing the sheets mapped by nameJxlsStyle
getStyle(java.lang.String name)
static void
main(java.lang.String[] args)
void
setDateFormat(java.lang.String dateFormat)
Sets the default format to use for integers when generating the xls This should be in the form "dd/MM/yy"void
setFloatFormat(java.lang.String floatFormat)
Sets the default format to use for numbers when generating the xls This should be in the form "###.0"void
setFontName(java.lang.String fontName)
Sets the default font to use when generating the xlsvoid
setFontSize(short fontSize)
Sets the default font size to use when generating the xlsvoid
setIntegerFormat(java.lang.String integerFormat)
Sets the default format to use for integers when generating the xls This should be in the form "### ###"void
write(java.io.OutputStream os)
Writes the xls to an OutputStreamvoid
write(javax.servlet.http.HttpServletResponse response)
Writes the xls to an HttpServletResponse, setting the correct mime type and headers
-
-
-
Field Detail
-
styles
protected java.util.Map<java.lang.String,JxlsStyle> styles
-
fonts
protected java.util.Map<java.lang.String,org.apache.poi.ss.usermodel.Font> fonts
-
sheets
protected java.util.Vector<JxlsSheet> sheets
-
sheetNames
protected java.util.Map<java.lang.String,JxlsSheet> sheetNames
-
poiWorkbook
protected org.apache.poi.ss.usermodel.Workbook poiWorkbook
-
-
Constructor Detail
-
JxlsWorkbook
public JxlsWorkbook(java.lang.String name)
Constructs an empty JxlsWorkbook- Parameters:
name
- : the name of the JxlsWorkbook
-
JxlsWorkbook
public JxlsWorkbook(javax.swing.table.TableModel table, java.lang.String name)
Constructs a JxlsWorkbook containing the data of the table- Parameters:
table
- : a Swing table modelname
- : the name of the Workbook
-
JxlsWorkbook
public JxlsWorkbook(java.io.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 Detail
-
getFontName
public java.lang.String getFontName()
-
setFontName
public void setFontName(java.lang.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 java.lang.String getFloatFormat()
-
setFloatFormat
public void setFloatFormat(java.lang.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 java.lang.String getIntegerFormat()
-
setIntegerFormat
public void setIntegerFormat(java.lang.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 java.lang.String getDateFormat()
-
setDateFormat
public void setDateFormat(java.lang.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(java.lang.String format)
-
addStyle
public JxlsStyle addStyle(java.lang.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 styletype
- the type of value managed by the style (one of: TEXT, INTEGER, FLOAT, DATE)- Returns:
- the JxlsStyle
-
addStyle
public JxlsStyle addStyle(java.lang.String name, java.lang.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 styleformat
- the format the style should use ("#.0%")- Returns:
- the JxlsStyle
-
addClonedStyle
public JxlsStyle addClonedStyle(java.lang.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 stylestyle
- the style to clone- Returns:
- the cloned JxlsStyle
-
getStyle
public JxlsStyle getStyle(java.lang.String name)
-
addSheet
public JxlsSheet addSheet(java.lang.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(java.lang.String name, int index)
Creates a JxlsSheet in which cells can be added- Parameters:
name
- the name which will appear on the tabindex
- 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(java.lang.String name)
Gets a sheet through its name- Parameters:
name
- the name of the sheet- Returns:
- the JxlsSheet
-
getSheets
public java.util.Vector<JxlsSheet> getSheets()
Gets the list of sheets- Returns:
- a Vector
-
getSheetsMap
public java.util.Map<java.lang.String,JxlsSheet> getSheetsMap()
Gets a map containing the sheets mapped by name- Returns:
- a Map
-
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(java.io.OutputStream os) throws java.lang.Exception
Writes the xls to an OutputStream- Parameters:
os
- the OutputStream to write to- Throws:
java.lang.Exception
- if the OutputStream can not be opened
-
write
public void write(javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
Writes the xls to an HttpServletResponse, setting the correct mime type and headers- Parameters:
response
- the HttpServletResponse to write to- Throws:
java.lang.Exception
- if the HttpServletResponse can not be written
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-