Click or drag to resize
Accord.NET (logo)

ExcelReader Class

Excel file reader using Microsoft Jet Database Engine.
Inheritance Hierarchy
SystemObject
  Accord.IOExcelReader

Namespace:  Accord.IO
Assembly:  Accord.IO (in Accord.IO.dll) Version: 3.8.0
Syntax
public class ExcelReader
Request Example View Source

The ExcelReader type exposes the following members.

Constructors
  NameDescription
Public methodExcelReader(String)
Creates a new spreadsheet reader.
Public methodExcelReader(Stream, Boolean)
Creates a new spreadsheet reader.
Public methodExcelReader(String, Boolean)
Creates a new spreadsheet reader.
Public methodExcelReader(Stream, Boolean, Boolean)
Creates a new spreadsheet reader.
Public methodExcelReader(String, Boolean, Boolean)
Creates a new spreadsheet reader.
Public methodExcelReader(Stream, Boolean, Boolean, Boolean)
Creates a new spreadsheet reader.
Top
Properties
  NameDescription
Public propertyHasHeaders
Gets whether the workbook has column headers.
Public propertyHasMixedData
Gets whether the data contains mixed string and numeric data.
Public propertyProvider
Gets the data provider used by the reader.
Public propertyVersion
Gets the Excel version used by the reader.
Public propertyWorksheetNames
Gets the names of the distinct sheets that are contained in the Excel file.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetColumnsList
Gets the list of columns in a worksheet.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetWorksheet
Gets the entire worksheet as a data set.
Public methodGetWorksheet(Int32)
Gets an worksheet as a data table.
Public methodGetWorksheet(String)
Gets an worksheet as a data table.
Public methodGetWorksheetList
Gets the list of worksheets in the spreadsheet.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

This class requires the Microsoft Access Database Engine to work. The download is available from Microsoft under the name "Microsoft Access Database Engine 2010 Redistributable", available in both 32-bit (x86) and 64-bit (x64) versions.

By default, the redistributable package will only install if it is the same as the current version of Microsoft Office installed in the machine (i.e. ACE 32-bit can not be installed with 64-bit office and vice-versa). To overcome this limitation and install both versions of the ACE drivers, specify /passive as a command line argument when installing the packages.

Examples
// Create a new reader, opening a given path
ExcelReader reader = new ExcelReader(path);

// Afterwards, we can query the file for all
// worksheets within the specified workbook:
string[] sheets = reader.GetWorksheetList();

// Finally, we can request an specific sheet:
DataTable table = reader.GetWorksheet(sheets[1]);

// Now, we have loaded the Excel file into a DataTable. We
// can go further and transform it into a matrix to start
// running other algorithms on it: 

double[,] matrix = table.ToMatrix();

// We can also do it retrieving the name for each column:
string[] columnNames; matrix = table.ToMatrix(out columnNames);

// Or we can extract specific columns into single arrays:
double[] column = table.Columns[0].ToArray();

// PS: you might need to import the Accord.Math namespace in
//   order to be able to call the ToMatrix extension methods.
See Also