MindFusion.Spreadsheet: Import and Export

The following scheme illustrates the file formats supported by MindFusion.Spreadsheet for WinForms:

spreadsheet-formats

Importing

MindFusion.Spreadsheet can load data from CSV (comma-separated values), XLSX (Office Open XML), ODS (OpenDocument Spreadsheet), and its native binary and XML formats. The files are imported through a set of importer classes: CsvImporter for CSV, ExcelImporter for XLSX, and CalcImporter for ODS. To import a file, create an instance of the respective importer class, set the necessary properties, and call its Import method. The following code demonstrates how to import a workbook from an existing XLSX file:

var excelImporter = new ExcelImporter();
excelImporter.Import(workbook, @"d:\workbook.xlsx");

Importing from CSV can be further facilitated through the use of a built-in CsvImportForm. The form provides the user interface to enter various options and preview the data before it is actually imported.

Exporting

MindFusion.Spreadsheet can export data to a variety of formats, including image, PDF, CSV, XLSX, ODS, HTML and MHTML. In addition the workbooks can be previewed and printed to paper and XPS. The workbooks and worksheets are exported through a set of exporter classes: ImageExporter for images, PdfExporter for PDF, CsvExporter for CSV, ExcelExporter for XLSX, CalcExporter for ODS, HtmlExporter for XHTML, and so on. Printing is done through the WorkbookPrinter class. To export a workbook, create an instance of the respective exporter class, set the necessary properties, and call the Export method. The following code demonstrates how to export a workbook to ODS:

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

The following image illustrates a workbook exported to an XHTML file using the HtmlExporter class:

spreadsheet-xhtmlexport

Additional information about the importing and exporting capabilities of MindFusion.Spreadsheet can be found in the online documentation of the component:

http://www.mindfusion.eu/onlinehelp/spreadsheetwinforms/index.htm?Importing.htm
http://www.mindfusion.eu/onlinehelp/spreadsheetwinforms/index.htm?Exporting_0.htm

The trial version of MindFusion.Spreadsheet for WinForms can be downloaded from here:

Download MindFusion.Spreadsheet for WinForms Trial Version

About MindFusion.Spreadsheet for WinForms: A powerful .NET spreadsheet component with great capabilities for editing, styling and formatting large amounts of data.

WinForms.Spreadsheet: Sorting Data

In this blog we will discuss how to sort existing data in MindFusion.Spreadsheet for WinForms both programmatically and by using the built-in form.

Introduction

As with all previous blogs we start off by creating a new Windows Forms Application in Visual Studio and adding a WorkbookView control to the main form. The WorkbookView displays a Workbook with a single worksheet.

Initializing the data

The data that should be sorted is contained in an CSV (comma-separated value) file, which is loaded at the start of the application. Some minor formatting is applied to the imported data, such as emphasizing the header row. The columns are automatically resized to fit the content through the ResizeColumnsToFit method of the WorkbookView class.

Sorting programmatically

The sorting is performed by calling the Sort method of the Worksheet class and providing a SortOptions object. This object contains information about the sort, such as which row or column to sort by, the sort direction (horizontal or vertical) and so on. In this particular case, we sort the data by columns, therefore we specify TopToBottom for the sort direction:

sortOptions.Direction = SortDirection.TopToBottom;

The columns (or rows) to sort by are specified by SortKey objects, added to the Keys collection of the SortOptions class. The order of the keys in the collection is important. For example, to sort by the first column and then by the fourth column, we define the following keys:

sortOptions.Keys.Add(new SortKey(0));
sortOptions.Keys.Add(new SortKey(3));

The Sort method accepts as argument the range to be sorted. In this sample we would like to prevent the header row from being sorted and specify A2:D15 for the target range.

The following image shows the running sample:

spreadsheet-sorting

Sorting through the built-in form

Sorting can also be performed through the built-in SortForm form, contained in the MindFusion.Spreadsheet.WinForms.StandardForms.dll assembly. The image below displays the form with the first and fourth columns selected as sort keys:

spreadsheet-sortform

The source code is available for download from here:

https://mindfusion.eu/_samples/SpreadsheetSorting.zip

The trial version of MindFusion.Spreadsheet for WinForms can be downloaded from here:

Download MindFusion.Spreadsheet for WinForms Trial Version

About MindFusion.Spreadsheet for WinForms: A powerful .NET spreadsheet component with great capabilities for editing, styling and formatting large amounts of data.

MindFusion.Spreadsheet for WinForms Beta Version

MindFusion.Spreadsheet is a spreadsheet component that can be used to create, open, manage, and export spreadsheet documents in many different formats without requiring Microsoft Excel. It is implemented as a .NET control and can be easily integrated into any application targeting the Microsoft .NET platform.

MindFusion.Spreadsheet supports:

  • Importing documents from CSV, XLSX, ODS
  • Export to PDF,CSV,image
  • Numerous chart types
  • Customizable cell appearance
  • Merged cells
  • Conditional formatting
  • Data validation
  • Images
  • Cell annotations
  • Previewing and printing
  • Undo and redo
  • Auxiliary forms
MindFusion.Spreadsheet lets you use an impressive range of calculation formulas.

MindFusion.Spreadsheet lets you use an impressive range of calculation formulas.

MindFusion.Spreadsheet provides intuitive user-interaction model for creating or editing spreadsheet documents. Its programmatic interface is powerful and simple to use. The control has been tested with the most popular .NET development environments and programming languages.

The beta version of the component is available for download from this link:

Download MindFusion.Spreadsheet for WinForms Beta Version

You can learn more about the features of the component here. Take a look at the gallery, which illustrates some of the capabilities of the control. Online documentation is also available at this link.

For technical support, please write at the forum or use email support@mindfusion.eu. You can also use the help desk.

Numerous chart types are available.

Numerous chart types are available.