HSSFRow headerRow = sheet.createRow(0);
Column[] columns = metaData.getColumns();
for (int j = 0; j < columns.length; j++)
{
Column column = columns[j];
HSSFCell cell = headerRow.createCell(j);
cell.setCellValue(new HSSFRichTextString(column.getColumnName()));
}
// write table data
for (int j = 0; j < table.getRowCount(); j++)
{
HSSFRow row = sheet.createRow(j + 1);
for (int k = 0; k < columns.length; k++)
{
Column column = columns[k];
Object value = table.getValue(j, column.getColumnName());
if (value != null)
{
HSSFCell cell = row.createCell(k);
if(value instanceof Date){
setDateCell(cell, (Date)value, workbook);