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:

C#  Copy Code

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

Visual Basic  Copy Code

Dim calcExporter As 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 Export method. The following example illustrates how to do this:

C#  Copy Code

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

Visual Basic  Copy Code

Dim excelExporter As New ExcelExporter()
excelExporter.Export(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:

C#  Copy Code

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

Visual Basic  Copy Code

Dim imageExporter As 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 (found in the MindFusion.Spreadsheet.WinForms.dll assembly) can be used to facilitate the export to CSV.

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

C#  Copy Code

var csvExporter = new CsvExporter();
csvExporter.Export(worksheet, @"d:\mysheet.csv");

Visual Basic  Copy Code

Dim csvExporter As New CsvExporter()
csvExporter.Export(worksheet, "d:\mysheet.csv")

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:

C#  Copy Code

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

Visual Basic  Copy Code

Dim pdfExporter As 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:

C#  Copy Code

var htmlExporter = new HtmlExporter();
htmlExporter.Export(workbook, @"d:\mysheet.html");

Visual Basic  Copy Code

Dim htmlExporter As New HtmlExporter()
htmlExporter.Export(workbook, "d:\mysheet.html")

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.