|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jidesoft.hssf.HssfTableUtils
public class HssfTableUtils
HssfTableUtils
is a class that has methods to export any JTable's content to Excel (.xls) file format
using HSSF-POI. You can find more information about HSSF-POI at http://poi.apache.org/spreadsheet/index.html.
CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT
for the target JTable before you invoke
this method so that you can choose the output format. If you didn't set the client property, we will use office2003
format for backward compatibility concern.
Please be noted that, if you use office2003 format, there is a limitation that the row count cannot exceed 65536.
Although office2007 format looks solve the issue, it will consume extremely high memory which in most case is not
realistic. So in general, we currently have limitation that the row count cannot exceed 65536.
Nested Class Summary | |
---|---|
static interface |
HssfTableUtils.CellValueConverter
Converts the cell value in a table to the value that will be written to Excel cell. |
static class |
HssfTableUtils.ContextSensitiveCellValueConverter
Converts the cell value in a table to the value that will be written to Excel cell. |
static class |
HssfTableUtils.DefaultCellValueConverter
Converts the cell value in a table to the value that will be written to Excel cell. |
static interface |
HssfTableUtils.POICustomizer
The POI customizer class which will be invoked after JIDE finish every settings for the cell. |
Field Summary | |
---|---|
static String |
CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT
The format for the component to export to excel. |
static String |
CLIENT_PROPERTY_FLUSH_ROWS
The maximum rows to flush memory when exporting to EXCEL_OUTPUT_FORMAT_2007 and CLIENT_PROPERTY_USE_SXSSF_WORKBOOK is true. |
static String |
CLIENT_PROPERTY_USE_SXSSF_WORKBOOK
The property to use SXSSFWorkbook when exporting to EXCEL_OUTPUT_FORMAT_2007 . |
static String |
EXCEL_OUTPUT_FORMAT_2003
A value for CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT to support format on Microsoft Office 2003 and earlier
versions. |
static String |
EXCEL_OUTPUT_FORMAT_2007
A value for CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT to support format on Microsoft Office 2007 and later
versions. |
Constructor Summary | |
---|---|
HssfTableUtils()
|
Method Summary | |
---|---|
static boolean |
export(JTable table,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
String fileName,
String sheetName,
boolean append,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter converter)
Exports the table to an Excel file. |
static boolean |
export(JTable table,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
String fileName,
String sheetName,
boolean append,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter,
StringConverter columnNameConverter)
Exports the table to an Excel file. |
static boolean |
export(JTable table,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
String fileName,
String sheetName,
boolean append,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter,
StringConverter columnNameConverter,
HssfTableUtils.POICustomizer customizer)
Exports the table to an Excel file. |
static boolean |
export(JTable table,
OutputStream out,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
String sheetName,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter)
Exports the table to as Excel file output steam. |
static boolean |
export(JTable table,
OutputStream out,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
String sheetName,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter,
StringConverter columnNameConverter)
Exports the table to as Excel file output steam. |
static boolean |
export(JTable table,
OutputStream out,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
String sheetName,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter,
StringConverter columnNameConverter,
HssfTableUtils.POICustomizer customizer)
Exports the table to as Excel file output steam. |
static boolean |
export(JTable table,
OutputStream out,
String sheetName)
Exports the table to as Excel file output steam. |
static boolean |
export(JTable table,
OutputStream out,
String sheetName,
boolean includeTableHeader)
Exports the table to as Excel file output steam. |
static boolean |
export(JTable table,
OutputStream out,
String sheetName,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter converter)
Exports the table to as Excel file output steam. |
static boolean |
export(JTable table,
String fileName,
String sheetName,
boolean append)
Exports the table to an Excel file. |
static boolean |
export(JTable table,
String fileName,
String sheetName,
boolean append,
boolean includeTableHeader)
Exports the table to an Excel file. |
static boolean |
export(JTable table,
String fileName,
String sheetName,
boolean append,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter converter)
Exports the table to an Excel file. |
static void |
exportToCell(Sheet sheet,
int rowIndex,
int columnIndex,
Object value)
Exports a value to a particular cell in the sheet. |
static void |
exportToSheet(JTable table,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
int firstRow,
int firstColumn,
int numberOfRows,
int numberOfColumns,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter cellValueConverter,
StringConverter columnNameConverter,
HssfTableUtils.POICustomizer customizer)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
Workbook wb,
Sheet sheet,
HssfTableFormat format)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn,
boolean includeTableHeader)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter converter)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn,
boolean includeTableHeader,
HssfTableUtils.CellValueConverter converter,
StringConverter columnNameConverter)
Exports the table to the specified location of an Excel sheet. |
static void |
exportToSheet(JTable table,
Workbook wb,
Sheet sheet,
int startRow,
int startColumn,
HssfTableUtils.CellValueConverter converter)
Exports the table to the specified location of an Excel sheet. |
static boolean |
isHssfInstalled()
Check if poi.jar is in the classpath. |
static boolean |
isXssfInstalled()
Check if poi.jar is in the classpath. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT
EXCEL_OUTPUT_FORMAT_2003
,
EXCEL_OUTPUT_FORMAT_2007
,
Constant Field Valuespublic static final String CLIENT_PROPERTY_USE_SXSSF_WORKBOOK
EXCEL_OUTPUT_FORMAT_2007
.
By default, XSSFWorkbook will be used to get maximum function. However, this default mode will consume many
memory. If you have a really huge table to export, please consider set this property to true. The trade-off is
that no spanning and grouping information will be exported to the excel file.
public static final String CLIENT_PROPERTY_FLUSH_ROWS
EXCEL_OUTPUT_FORMAT_2007
and CLIENT_PROPERTY_USE_SXSSF_WORKBOOK
is true.
public static final String EXCEL_OUTPUT_FORMAT_2003
CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT
to support format on Microsoft Office 2003 and earlier
versions.
public static final String EXCEL_OUTPUT_FORMAT_2007
CLIENT_PROPERTY_EXCEL_OUTPUT_FORMAT
to support format on Microsoft Office 2007 and later
versions.
Constructor Detail |
---|
public HssfTableUtils()
Method Detail |
---|
public static boolean isHssfInstalled()
export
methods in this util called this method first
before continuing.
public static boolean isXssfInstalled()
export
methods in this util called this method first
before continuing.
public static boolean export(JTable table, String fileName, String sheetName, boolean append) throws IOException
table
- the table to be exported.fileName
- the Excel file name. It should be the full path to the file.sheetName
- the worksheet name.append
- whether it appends to the existing Excel file or it creates a new Excel file.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, String fileName, String sheetName, boolean append, boolean includeTableHeader) throws IOException
table
- the table to be exported.fileName
- the Excel file name. It should be the full path to the file.sheetName
- the worksheet name.append
- whether it appends to the existing Excel file or it creates a new Excel file.includeTableHeader
- whether to include the table header.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, String fileName, String sheetName, boolean append, boolean includeTableHeader, HssfTableUtils.CellValueConverter converter) throws IOException
table
- the table to be exported.fileName
- the Excel file name. It should be the full path to the file.sheetName
- the worksheet name.append
- whether it appends to the existing Excel file or it creates a new Excel file.includeTableHeader
- whether to include the table header.converter
- the converter to convert cell value to the value that can be set to Excel cell.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, String fileName, String sheetName, boolean append, boolean includeTableHeader, HssfTableUtils.CellValueConverter converter) throws IOException
table
- the table to be exported.firstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.fileName
- the Excel file name. It should be the full path to the file.sheetName
- the worksheet name.append
- whether it appends to the existing Excel file or it creates a new Excel file.includeTableHeader
- whether to include the table header.converter
- the converter to convert cell value to the value that can be set to Excel cell.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, String fileName, String sheetName, boolean append, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter, StringConverter columnNameConverter) throws IOException
table
- the table to be exported.firstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.fileName
- the Excel file name. It should be the full path to the file.sheetName
- the worksheet name.append
- whether it appends to the existing Excel file or it creates a new Excel file.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.columnNameConverter
- the converter to convert the column name.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, String fileName, String sheetName, boolean append, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter, StringConverter columnNameConverter, HssfTableUtils.POICustomizer customizer) throws IOException
table
- the table to be exported.firstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.fileName
- the Excel file name. It should be the full path to the file.sheetName
- the worksheet name.append
- whether it appends to the existing Excel file or it creates a new Excel file.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.columnNameConverter
- the converter to convert the column name.customizer
- the customizer to customize a POI cell and the entire sheet.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, OutputStream out, String sheetName) throws IOException
table
- the table to be exported.out
- the output streamsheetName
- the worksheet name.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, OutputStream out, String sheetName, boolean includeTableHeader) throws IOException
table
- the table to be exported.out
- the output streamsheetName
- the worksheet name.includeTableHeader
- whether to include the table header.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, OutputStream out, String sheetName, boolean includeTableHeader, HssfTableUtils.CellValueConverter converter) throws IOException
table
- the table to be exported.out
- the output streamsheetName
- the worksheet name.includeTableHeader
- whether to include the table header.converter
- the converter to convert cell value to the value that can be set to Excel cell.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, OutputStream out, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, String sheetName, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter) throws IOException
table
- the table to be exported.out
- the output streamfirstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.sheetName
- the worksheet name.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, OutputStream out, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, String sheetName, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter, StringConverter columnNameConverter) throws IOException
table
- the table to be exported.out
- the output streamfirstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.sheetName
- the worksheet name.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.columnNameConverter
- the converter to convert the column name.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static boolean export(JTable table, OutputStream out, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, String sheetName, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter, StringConverter columnNameConverter, HssfTableUtils.POICustomizer customizer) throws IOException
table
- the table to be exported.out
- the output streamfirstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.sheetName
- the worksheet name.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.columnNameConverter
- the converter to convert the column name.customizer
- the customizer to customize a POI cell and the entire sheet.
IOException
- if the write to the file failed.
FileNotFoundException
- if the file exists but is a directory rather than a regular file, does not
exist but cannot be created, or cannot be opened for any other reasonpublic static void exportToSheet(JTable table, Workbook wb, Sheet sheet, int startRow, int startColumn)
table
- the table to be exported.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.public static void exportToSheet(JTable table, Workbook wb, Sheet sheet, int startRow, int startColumn, HssfTableUtils.CellValueConverter converter)
table
- the table to be exported.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.converter
- the converter to convert cell value to the value that can be set to Excel cell.public static void exportToSheet(JTable table, Workbook wb, Sheet sheet, int startRow, int startColumn, boolean includeTableHeader)
table
- the table to be exported.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.includeTableHeader
- whether to include the table header.public static void exportToSheet(JTable table, Workbook wb, Sheet sheet, int startRow, int startColumn, boolean includeTableHeader, HssfTableUtils.CellValueConverter converter)
table
- the table to be exported.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.includeTableHeader
- whether to include the table header.converter
- the converter to convert cell value to the value that can be set to Excel cell.public static void exportToSheet(JTable table, Workbook wb, Sheet sheet, int startRow, int startColumn, boolean includeTableHeader, HssfTableUtils.CellValueConverter converter, StringConverter columnNameConverter)
table
- the table to be exported.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.includeTableHeader
- whether to include the table header.converter
- the converter to convert cell value to the value that can be set to Excel cell.columnNameConverter
- the converter to convert the column name.public static void exportToSheet(JTable table, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, Workbook wb, Sheet sheet, int startRow, int startColumn, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter)
table
- the table to be exported.firstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.public static void exportToSheet(JTable table, int firstRow, int firstColumn, int numberOfRows, int numberOfColumns, Workbook wb, Sheet sheet, int startRow, int startColumn, boolean includeTableHeader, HssfTableUtils.CellValueConverter cellValueConverter, StringConverter columnNameConverter, HssfTableUtils.POICustomizer customizer)
table
- the table to be exported.firstRow
- the first row to be exportedfirstColumn
- the first row to be exportednumberOfRows
- number of rows to be exported, -1 means all rows.numberOfColumns
- number of columns to be exported. -1 means all columns.wb
- the Workbooksheet
- the worksheetstartRow
- the starting row. The first cell of the table will appear at this row index.startColumn
- the starting column. The first cell of the table will appear at this row index.includeTableHeader
- whether to include the table header.cellValueConverter
- the converter to convert cell value to the value that can be set to Excel cell.columnNameConverter
- the converter to convert the column name.customizer
- the customizer to customize a POI cell, the POI row and the entire sheet.public static void exportToSheet(JTable table, Workbook wb, Sheet sheet, HssfTableFormat format)
table
- the table to be exported.wb
- the Workbooksheet
- the worksheetformat
- HssfTableFormat instance which stores every single information needed for exporting to sheetpublic static void exportToCell(Sheet sheet, int rowIndex, int columnIndex, Object value)
sheet
- the worksheetrowIndex
- the row index of the cellcolumnIndex
- the column index of the cellvalue
- the value
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |