public class JxlsWorkbook extends java.lang.Object implements JxlsConstants
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"));
Modifier and Type | Field and 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 |
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 and Description |
---|
JxlsWorkbook(java.io.File xlsFile)
Constructs a JxlsWorkbook and fills it with the raw data of the input file
styles are not copied
|
JxlsWorkbook(java.lang.String name)
Constructs an empty JxlsWorkbook
|
JxlsWorkbook(javax.swing.table.TableModel table,
java.lang.String name)
Constructs a JxlsWorkbook containing the data of the table
|
Modifier and Type | Method and Description |
---|---|
JxlsStyle |
addClonedStyle(JxlsStyle style) |
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)
|
JxlsSheet |
addSheet(java.lang.String name)
Creates a JxlsSheet in which cells can be added
|
JxlsSheet |
addSheet(java.lang.String name,
int index)
Creates a JxlsSheet in which cells can be added
|
JxlsStyle |
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 JxlsWorkbok
|
void |
deletePOIWorkbook()
Resets the Apache POI Workbook from the JxlsWorkbok to regenerate the Workbook on next createPOIWorkbook
|
void |
deleteSheet(int index)
Deletes a JxlsSheet
|
java.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 index
|
JxlsSheet |
getSheet(java.lang.String name)
Gets a sheet through its name
|
java.util.Vector<JxlsSheet> |
getSheets()
Gets the list of sheets
|
java.util.Map<java.lang.String,JxlsSheet> |
getSheetsMap()
Gets a map containing the sheets mapped by name
|
JxlsStyle |
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 xls
|
void |
setFontSize(short fontSize)
Sets the default font size to use when generating the xls
|
void |
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(HttpServletResponse response)
Writes the xls to an HttpServletResponse, setting the correct mime type and headers
|
void |
write(java.io.OutputStream os)
Writes the xls to an OutputStream
|
protected java.util.Map<java.lang.String,JxlsStyle> styles
protected java.util.Map<java.lang.String,org.apache.poi.ss.usermodel.Font> fonts
protected java.util.Vector<JxlsSheet> sheets
protected java.util.Map<java.lang.String,JxlsSheet> sheetNames
protected org.apache.poi.ss.usermodel.Workbook poiWorkbook
public JxlsWorkbook(java.lang.String name)
name:
- the name of the JxlsWorkbookpublic JxlsWorkbook(javax.swing.table.TableModel table, java.lang.String name)
table:
- a Swing table modelname:
- the name of the Workbookpublic JxlsWorkbook(java.io.File xlsFile)
xlsFile:
- an xls filepublic java.lang.String getFontName()
public void setFontName(java.lang.String fontName)
fontName:
- the name of the fontpublic short getFontSize()
public void setFontSize(short fontSize)
fontSize:
- the point size of the fontpublic java.lang.String getFloatFormat()
public void setFloatFormat(java.lang.String floatFormat)
floatFormat:
- the formatpublic java.lang.String getIntegerFormat()
public void setIntegerFormat(java.lang.String integerFormat)
integerFormat:
- the formatpublic java.lang.String getDateFormat()
public void setDateFormat(java.lang.String dateFormat)
dateFormat:
- the formatpublic JxlsStyle getDefaultStyle()
public JxlsStyle getDefaultDateStyle()
public JxlsStyle getDefaultFloatStyle()
public JxlsStyle addStyle(int type)
public JxlsStyle addStyle(java.lang.String format)
public JxlsStyle addStyle(java.lang.String name, int type)
name
- the name to use when recalling the styletype
- the type of value managed by the style (one of: TEXT, INTEGER, FLOAT, DATE)public JxlsStyle addStyle(java.lang.String name, java.lang.String format)
name
- the name to use when recalling the styleformat
- the format the style should use ("#.0%")public JxlsStyle addClonedStyle(java.lang.String name, JxlsStyle style)
name
- the name to use when recalling the stylestyle
- the style to clonepublic JxlsStyle getStyle(java.lang.String name)
public JxlsSheet addSheet(java.lang.String name)
name
- the name which will appear on the tabpublic JxlsSheet addSheet(java.lang.String name, int index)
name
- the name which will appear on the tabindex
- the index at which the sheet should appear in the tab listpublic void deleteSheet(int index)
index
- the index of the tab to deletepublic JxlsSheet getSheet(int index)
index
- the index of the sheetpublic JxlsSheet getSheet(java.lang.String name)
name
- the name of the sheetpublic java.util.Vector<JxlsSheet> getSheets()
public java.util.Map<java.lang.String,JxlsSheet> getSheetsMap()
public void deletePOIWorkbook()
public org.apache.poi.ss.usermodel.Workbook createPOIWorkbook()
public void write(java.io.OutputStream os) throws java.lang.Exception
os
- the OutputStream to write tojava.lang.Exception
- if the OutputStream can not be openedpublic void write(HttpServletResponse response) throws java.lang.Exception
response
- the HttpServletResponse to write tojava.lang.Exception
- if the HttpServletResponse can not be writtenpublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception