Package org.openxava.util.jxls
Class JxlsWorkbook
java.lang.Object
org.openxava.util.jxls.JxlsWorkbook
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.poi.ss.usermodel.WorkbookFields 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
ConstructorsConstructorDescriptionJxlsWorkbook(File xlsFile) Constructs a JxlsWorkbook and fills it with the raw data of the input file styles are not copiedJxlsWorkbook(String name) Constructs an empty JxlsWorkbookJxlsWorkbook(TableModel table, String name) Constructs a JxlsWorkbook containing the data of the table -
Method Summary
Modifier and TypeMethodDescriptionaddClonedStyle(String name, JxlsStyle style) Creates a JxlsStyle based upon another existing JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)addClonedStyle(JxlsStyle style) Creates a JxlsSheet in which cells can be addedCreates a JxlsSheet in which cells can be addedaddStyle(int type) Creates a JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)Creates a JxlsStyle which can be referenced when using sheet.setValue(column, row, value, style)org.apache.poi.ss.usermodel.WorkbookCreates an apache POI Workbook from the JxlsWorkbokvoidResets the Apache POI Workbook from the JxlsWorkbok to regenerate the Workbook on next createPOIWorkbookvoiddeleteSheet(int index) Deletes a JxlsSheetshortgetSheet(int index) Gets a sheet through its indexGets a sheet through its nameGets the list of sheetsGets a map containing the sheets mapped by namestatic voidvoidsetDateFormat(String dateFormat) Sets the default format to use for integers when generating the xls This should be in the form "dd/MM/yy"voidsetFloatFormat(String floatFormat) Sets the default format to use for numbers when generating the xls This should be in the form "###.0"voidsetFontName(String fontName) Sets the default font to use when generating the xlsvoidsetFontSize(short fontSize) Sets the default font size to use when generating the xlsvoidsetIntegerFormat(String integerFormat) Sets the default format to use for integers when generating the xls This should be in the form "### ###"voidwrite(OutputStream os) Writes the xls to an OutputStreamvoidwrite(javax.servlet.http.HttpServletResponse response) Writes the xls to an HttpServletResponse, setting the correct mime type and headers
-
Field Details
-
styles
-
fonts
-
sheets
-
sheetNames
-
poiWorkbook
protected org.apache.poi.ss.usermodel.Workbook poiWorkbook
-
-
Constructor Details
-
JxlsWorkbook
Constructs an empty JxlsWorkbook- Parameters:
name- : the name of the JxlsWorkbook
-
JxlsWorkbook
Constructs a JxlsWorkbook containing the data of the table- Parameters:
table- : a Swing table modelname- : the name of the Workbook
-
JxlsWorkbook
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
-
setFontName
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
-
setFloatFormat
Sets the default format to use for numbers when generating the xls This should be in the form "###.0"- Parameters:
floatFormat- : the format
-
getIntegerFormat
-
setIntegerFormat
Sets the default format to use for integers when generating the xls This should be in the form "### ###"- Parameters:
integerFormat- : the format
-
getDateFormat
-
setDateFormat
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
-
getDefaultDateStyle
-
getDefaultFloatStyle
-
addStyle
-
addStyle
-
addClonedStyle
-
addStyle
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
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
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
-
addSheet
Creates a JxlsSheet in which cells can be added- Parameters:
name- the name which will appear on the tab- Returns:
- the JxlsSheet
-
addSheet
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
Gets a sheet through its index- Parameters:
index- the index of the sheet- Returns:
- the JxlsSheet
-
getSheet
Gets a sheet through its name- Parameters:
name- the name of the sheet- Returns:
- the JxlsSheet
-
getSheets
Gets the list of sheets- Returns:
- a Vector
-
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
Writes the xls to an OutputStream- Parameters:
os- the OutputStream to write to- Throws:
Exception- if the OutputStream can not be opened
-
write
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
- Throws:
Exception
-