TableWriterpublic class ExcelWriter extends AbstractStreamTableWriter
The Excel will be written with a call to 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 | 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(org.apache.poi.ss.usermodel.Workbook workbook) |
Constructor with existing workbook.
|
ExcelWriter(org.apache.poi.ss.usermodel.Workbook workbook,
File file) |
Constructor with existing workbook that needs to be written to a file.
|
ExcelWriter(org.apache.poi.ss.usermodel.Workbook workbook,
OutputStream out) |
Constructor with existing workbook and defined output stream.
|
ExcelWriter(org.apache.poi.ss.usermodel.Workbook workbook,
String file) |
Constructor with existing workbook that needs to be written to a file.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes the writer and writes the Excel to the underlying stream.
|
org.apache.poi.ss.usermodel.Sheet |
createSheet() |
Creates a new sheet for the workbook.
|
org.apache.poi.ss.usermodel.Sheet |
createSheet(int index) |
Creates a new sheet for the workbook at specified index.
|
org.apache.poi.ss.usermodel.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.
|
org.apache.poi.ss.usermodel.Cell |
getOrCreateCell(int row,
int column) |
Returns an existing cell or creates one.
|
org.apache.poi.ss.usermodel.Cell |
getOrCreateCell(org.apache.poi.ss.usermodel.Row row,
int column) |
Returns an existing cell or creates one.
|
org.apache.poi.ss.usermodel.Row |
getOrCreateRow(int row) |
Returns an existing row or creates one.
|
org.apache.poi.ss.usermodel.Sheet |
getSheet() |
Returns the current sheet or creates a fresh one.
|
org.apache.poi.ss.usermodel.Workbook |
getWorkbook() |
Returns the workbook or creates a fresh one.
|
protected void |
notifyExcelListeners(org.apache.poi.ss.usermodel.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.
|
org.apache.poi.ss.usermodel.Sheet |
selectSheet(int index) |
This method selects the sheet at given index.
|
void |
selectSheet(org.apache.poi.ss.usermodel.Sheet sheet) |
This method selects the given sheet.
|
void |
setFormatter(ExcelFormatter formatter) |
Sets the formatter for this ExcelWriter.
|
protected void |
setStyle(org.apache.poi.ss.usermodel.Cell cell,
Object value) |
Sets the style of a cell.
|
void |
setValue(int row,
int column,
Object value) |
Sets the value at the specified cell.
|
void |
setValue(org.apache.poi.ss.usermodel.Cell cell,
Object value) |
Sets the value at the specified cell.
|
void |
setValue(org.apache.poi.ss.usermodel.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(org.apache.poi.ss.usermodel.Workbook workbook)
workbook - the workbook to be usedAbstractStreamTableWriter.setOutputStream(OutputStream)public ExcelWriter(OutputStream out)
out - output stream to be used.public ExcelWriter(org.apache.poi.ss.usermodel.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(org.apache.poi.ss.usermodel.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(org.apache.poi.ss.usermodel.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 writtenIOException - when an error occurs while writingprintRow(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 org.apache.poi.ss.usermodel.Cell getOrCreateCell(int row,
int column)
row - row indexcolumn - column indexpublic org.apache.poi.ss.usermodel.Cell getOrCreateCell(org.apache.poi.ss.usermodel.Row row,
int column)
row - row objectcolumn - column indexpublic org.apache.poi.ss.usermodel.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(org.apache.poi.ss.usermodel.Row row,
int column,
Object value)
row - row objectcolumn - column indexvalue - value to be setsetValue(Cell, Object)public void setValue(org.apache.poi.ss.usermodel.Cell cell,
Object value)
ExcelFormatter to set the correct style
on this cell.cell - cell objectvalue - value to be setpublic org.apache.poi.ss.usermodel.Workbook getWorkbook()
public org.apache.poi.ss.usermodel.Sheet getSheet()
public void selectSheet(org.apache.poi.ss.usermodel.Sheet sheet)
printRow(Object[])).sheet - sheet to be selectedpublic org.apache.poi.ss.usermodel.Sheet selectSheet(int index)
printRow(Object[])).index - sheet indexpublic org.apache.poi.ss.usermodel.Sheet createSheet()
public org.apache.poi.ss.usermodel.Sheet createSheet(int index)
index - of sheet (-1 adds the sheet at the end of all sheet)public org.apache.poi.ss.usermodel.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(org.apache.poi.ss.usermodel.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(org.apache.poi.ss.usermodel.Cell cell,
Object value)
ExcelFormatter.setStyle(ExcelWriter, Cell, Object).cell - cell to be formattedvalue - value that was setsetFormatter(ExcelFormatter)Copyright © 2018. All rights reserved.