ListObject table = worksheet.getListObjects().get(tableName);
Worksheet newWorksheet = table.getDataRange().getWorksheet();
Range sourceRange = table.getDataRange();
if (table.getShowHeaderRow())
{
//Include table’s header row
int fcol = sourceRange.getFirstColumn();
int frow = sourceRange.getFirstRow() - 1;
// including the first header row.
int rowCount = sourceRange.getRowCount() + 1;
// including the first header row.
int colCount = sourceRange.getColumnCount();
sourceRange = newWorksheet.getCells().createRange(frow, fcol, rowCount, colCount);
}
Workbook newWorkbook = new Workbook(FileFormatType.XLSX);
WorksheetCollection targetWsc = newWorkbook.getWorksheets();
Worksheet targetWs = (Worksheet)targetWsc.get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
//Copy column widths
options.setPasteType(PasteType.COLUMN_WIDTHS);
targetRange.copy(sourceRange, options);
// Copy row heights
int rowCount = sourceRange.getRowCount();
int firstRow = sourceRange.getFirstRow();
for (int i = 0; i < rowCount; i++) {
double rowHeight = sourceRange.getWorksheet().getCells().getRowHeight(firstRow++);
targetWs.getCells().setRowHeight(i, rowHeight);
}
//Copy everything else
options.setPasteType(PasteType.ALL);
targetRange.copy(sourceRange, options);
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions(SaveFormat.HTML);
htmlSaveOptions.setParseHtmlTagInCell(true);
newWorkbook.save(“D:\test.html”, htmlSaveOptions);