Search
Exporting

Exporting to ODS

To export a workbook to an ODS (OpenDocument Spreadsheet) file, create an instance of the CalcExporter class and call the export method. The following example illustrates how to do this:

Java  Copy Code

CalcExporter calcExporter = new CalcExporter();
calcExporter.export(workbook, "c:\\mysheet.ods");

Exporting to XLSX

To export a workbook to an XLSX (Office Open XML) file, create an instance of the ExcelExporter class and call the exportXlsx method. The following example illustrates how to do this:

Java  Copy Code

ExcelExporter excelExporter = new ExcelExporter();
excelExporter.exportXlsx(workbook, "c:\\mysheet.xlsx");

Exporting Bitmap Images

You can create a static image representing the worksheet of a workbook by using the ImageExporter class. To do this, create an instance of the ImageExporter class, set the desired properties and call the export method. To export a subset of cells in the worksheet, use the CellRange property of the exporter. The grid lines and interactive objects can be enabled or disabled through the EnableGridLines and EnableObjects properties respectively. The image format and the maximum size of the image can be specified through the ImageFormat and MaxImageSize properties. To get the cells that were actually exported by the most recent call to export, call the getExportedRange method. This can be useful when exporting big worksheets that cannot fit in a single image.

The following example illustrates how to export an existing worksheet:

Java  Copy Code

ImageExporter imageExporter = new ImageExporter();
imageExporter.export(worksheet, "c:\\mysheet.png");

Exporting to CSV

To export a worksheet to an CSV (comma-separated values) file, create an instance of the CsvExporter class, set the appropriate properties and call the export method. The Quote and Separator properties can be used to specify the quote and separator characters respectively in the exported file. The CsvExportForm can be used to facilitate the export to CSV.

The following example illustrates how to export a worksheet to an CSV file:

Java  Copy Code

CsvExporter csvExporter = new CsvExporter();
try
{
    csvExporter.export(worksheet, "d:\\mysheet.csv");
}
catch (IOException ex)
{
}

Exporting to PDF

To export a worksheet to a PDF file, create an instance of the PdfExporter class, set the appropriate properties and call the export method. The following example illustrates how to do this:

Java  Copy Code

PdfExporter pdfExporter = new PdfExporter();
pdfExporter.export(worksheet, "d:\\mysheet.pdf");

Exporting to XHTML and MHTML

To export a workbook to a XHTML or MHTML file, create an instance of the HtmlExporter or MhtmlExporter class respecively, set the appropriate properties and call the export method. The following example illustrates how to do this:

Java  Copy Code

HtmlExporter htmlExporter = new HtmlExporter();
try
{
    htmlExporter.export(workbook, "d:\\mysheet.html");
}
catch (IOException ex)
{
}

The two exporter classes derive several properties from their common base class HtmlExporterBase, namely, Title, Encoding, EnablePictures, EnableCharts, and EnableGridLines. In addition to these, the HtmlExporter class provides a set of properties that specify how images are stored EmbedImages, RootFolder, and ImageFolder.

Restrictions

The section highlights some of the limitations of the XHTML/MHTML exporters.

  • Text cannot overflow in neighbouring cells it either wraps or gets clipped (depending on the value of the WrapOverflowingContent property). Wrapping will cause the row height to increase.
  • Rows cannot be smaller than their content.
  • Conditional formats are ignored.
  • Borders of filled cells cannot be hidden (see DrawFilledCellBorders).
  • Collapsed columns/rows do not affect appearance.
  • Images and charts in collapsed columns/rows are not exported.
  • Padding and indent in row/column styles are ignored.
  • Diagonal formatting is ignored.
  • Images displayed beyond the cells containing data may render on top of the subsequent worksheets.
  • Gradient brushes are exported as solid.