public class ExcelWriter extends AbstractStreamTableWriter
close() only!
Please notice that this implementation does not support writing formulas into
cells, yet.
Example:
java.io.File f = new java.io.File("excel-test.xls");
ExcelWriter out = new ExcelWriter(f);
out.printRow(new Object[] { "0:0", new Integer(3), new Date() });
out.printRow(new Object[] { "1:0", new Double(), "another String value" });
out.close();
close()| Constructor and Description |
|---|
ExcelWriter()
Default constructor.
|
ExcelWriter(File file)
Constructor for writing into a file.
|
ExcelWriter(OutputStream out)
Constructor with defined output stream.
|
ExcelWriter(String file)
Constructor for writing into a file.
|
ExcelWriter(Workbook workbook)
Constructor with existing workbook.
|
ExcelWriter(Workbook workbook,
File file)
Constructor with existing workbook that needs to be written to a file.
|
ExcelWriter(Workbook workbook,
OutputStream out)
Constructor with existing workbook and defined output stream.
|
ExcelWriter(Workbook workbook,
String file)
Constructor with existing workbook that needs to be written to a file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the writer and writes the Excel to the underlying stream.
|
Sheet |
createSheet()
Creates a new sheet for the workbook.
|
Sheet |
createSheet(int index)
Creates a new sheet for the workbook at specified index.
|
Sheet |
createSheet(int index,
String name)
Creates a new sheet for the workbook at specified index.
|
ExcelFormatter |
getFormatter()
Returns the formatter set for this ExcelWriter.
|
Cell |
getOrCreateCell(int row,
int column)
Returns an existing cell or creates one.
|
Cell |
getOrCreateCell(Row row,
int column)
Returns an existing cell or creates one.
|
Row |
getOrCreateRow(int row)
Returns an existing row or creates one.
|
Sheet |
getSheet()
Returns the current sheet or creates a fresh one.
|
Workbook |
getWorkbook()
Returns the workbook or creates a fresh one.
|
protected void |
notifyExcelListeners(Row row)
Notifies all Excel Listeners about the new row.
|
void |
printComment(String comment,
int row,
int column)
Prints a comment into the output stream.
|
void |
printRow(Object[] columns)
Prints the values to the Excel file.
|
void |
printRow(Object[] columns,
int rowNum)
Prints the values to the Excel file at the given row.
|
void |
registerExcelListener(ExcelListener l)
Registers an Excel Listener.
|
Sheet |
selectSheet(int index)
This method selects the sheet at given index.
|
void |
selectSheet(Sheet sheet)
This method selects the given sheet.
|
void |
setFormatter(ExcelFormatter formatter)
Sets the formatter for this ExcelWriter.
|
protected void |
setStyle(Cell cell,
Object value)
Sets the style of a cell.
|
void |
setValue(Cell cell,
Object value)
Sets the value at the specified cell.
|
void |
setValue(int row,
int column,
Object value)
Sets the value at the specified cell.
|
void |
setValue(Row row,
int column,
Object value)
Sets the value at the specified cell.
|
void |
unregisterExcelListener(ExcelListener l)
Unregisters an ExcelListener.
|
createOutputStreamWriter, createWriter, getCharsetEncoder, getOutputStream, getWriter, setCharset, setCharset, setCharsetEncoder, setOutputStreamconvert, convert, getRowCount, getTypeConversionHandler, incrementRowCount, init, printComment, printRow, printRow, printRow, registerTypeConversionHandler, unregisterTypeConversionHandlerpublic ExcelWriter()
public ExcelWriter(Workbook workbook)
workbook - the workbook to be usedAbstractStreamTableWriter.setOutputStream(OutputStream)public ExcelWriter(OutputStream out)
out - output stream to be used.public ExcelWriter(Workbook workbook, OutputStream out)
workbook - the workbook to be usedout - output stream to be usedpublic ExcelWriter(File file) throws IOException
file - output file to be usedIOException - when the file cannot be written topublic ExcelWriter(Workbook workbook, File file) throws IOException
workbook - the workbook to be usedfile - output file to be usedIOException - when the file cannot be written topublic ExcelWriter(String file) throws IOException
file - output file to be usedIOException - when the file cannot be written topublic ExcelWriter(Workbook workbook, String file) throws IOException
workbook - the workbook to be usedfile - output file to be usedIOException - when the file cannot be written topublic void printRow(Object[] columns) throws IOException
printRow(Object[], int)columns - values to be written to the Excel sheetIOException - when an exception occursTableWriter.printRow(java.lang.Object[])public void printRow(Object[] columns, int rowNum) throws IOException
columns - values to be written to the Excel sheetrowNum - index of row to be writtenIOExceptionprintRow(Object[])public void printComment(String comment, int row, int column) throws IOException
printComment in interface TableWriterprintComment in class AbstractTableWritercomment - the comment to writerow - index of row for commentcolumn - index of column for commentIOException - when an exception occurspublic Cell getOrCreateCell(int row, int column)
row - row indexcolumn - column indexpublic Cell getOrCreateCell(Row row, int column)
row - row objectcolumn - column indexpublic Row getOrCreateRow(int row)
ExcelListeners about a new row.row - row indexpublic void setValue(int row,
int column,
Object value)
row - row indexcolumn - column indexvalue - value to be setsetValue(Cell, Object)public void setValue(Row row, int column, Object value)
row - row objectcolumn - column indexvalue - value to be setsetValue(Cell, Object)public void setValue(Cell cell, Object value)
ExcelFormatter to set the correct style
on this cell.cell - cell objectvalue - value to be setpublic Workbook getWorkbook()
public Sheet getSheet()
public void selectSheet(Sheet sheet)
printRow(Object[])).sheet - sheet to be selectedpublic Sheet selectSheet(int index)
printRow(Object[])).index - sheet indexpublic Sheet createSheet()
public Sheet createSheet(int index)
index - of sheet (-1 adds the sheet at the end of all sheet)public Sheet createSheet(int index, String name)
name - name of new sheetindex - of sheet (-1 adds the sheet at the end of all sheet)public void close()
close in interface TableWriterclose in class AbstractStreamTableWriterAbstractStreamTableWriter.close()public void registerExcelListener(ExcelListener l)
l - the listenerpublic void unregisterExcelListener(ExcelListener l)
l - the listenerprotected void notifyExcelListeners(Row row)
row - the row that was createdpublic ExcelFormatter getFormatter()
public void setFormatter(ExcelFormatter formatter)
formatter - the formatter to setExcelFormatter,
setValue(Cell, Object),
setStyle(Cell, Object)protected void setStyle(Cell cell, Object value)
ExcelFormatter.setStyle(ExcelWriter, Cell, Object).cell - cell to be formattedvalue - value that was setsetFormatter(ExcelFormatter)Copyright © 2014. All rights reserved.