Project Description
Open-source extensions for the DataTable class of ADO.net representing in-memory tables in the .net framework. Provided by Finaquant Analytics with GNU GPL license (General Public License).

DataTable Extensions
Extensions include methods written in C# for DataTable operations like:

  • Convert  DataTable to a printable string
  • Export or import a DataTable object to/from a MatrixTable object of Finaquant Protos (non-commercial free .net library with table valued functions)
  • Export or import a DataTable object to/from an Microsoft Excel file
  • Export or import a DataTable object to/from a CSV file
  • Display DataTable with a Form containing a DataGridView
  • Column and/or row partitioning of a table

You may find the complete list of extension methods (initial version) in the table below. Note that these DataTable extensions require Finaquant Protos as one of the referenced assemblies.

You can download the Microsoft Visual Studio 2010 solution file which contains the initial source code of DataTable extensions including a demo function that demonstrates the usage of extension methods.

List of DataTable Extension Methods

Extension method Description
public static Type GetColumnDataType(this DataTable tbl, string ColumnName) Get data type of column
public static Type GetColumnDataType(this DataTable tbl, int ColumnIndex) Get data type of column
public static object GetElementValue(this DataTable tbl, string ColumnName, int RowInd) Get table element with given column names and row indices
public static void SetElementValue(this DataTable tbl, string ColumnName, int RowInd, object ElementValue) Assign value to a table element with given column and row indices
public static void ExportToExcelFile(this DataTable Tbl, string ExcelFilePath = null) Export DataTable into an excel file
public static DataTable ImportFromExcelFile(this DataTable Tbl, string Filepath, string SheetName) Read DataTable from a sheet of excel file
public static MatrixTable ConvertToMatrixTable(this DataTable tbl, MetaData md, string TextReplaceNull = "NULL", int NumReplaceNull = 0, double KeyFigReplaceNull = 0) Convert DataTable into a MatrixTable object
public static DataTable ImportFromMatrixTable(this DataTable tbl, MatrixTable mtbl) Convert TableMatrix into a DataTable object
public static void ExportToCSVfile(this DataTable Tbl, string filepath) Export DataTable to CSV file with semicolon as delimiter
public static void ExportToCSVfile(this DataTable Tbl) Export DataTable to CSV file with semicolon as delimiter
public static DataTable ImportFromCSVfile(this DataTable Tbl, MetaData md, string filepath) Import DataTable from CSV file (semicolon as delimiter)
public static string ConvertToString(this DataTable tbl) Convert DataTable into a printable string
public static DataTable PartitionColumn(this DataTable tbl, TextVector ColumnNames) Column partition: Return a DataTable with selected columns
public static DataTable PartitionColumn(this DataTable tbl, NumVector ColumnIndices) Return subtable with selected column indices
public static DataTable PartitionRow(this DataTable tbl, NumVector RowIndices) Return subtable with selected row indices
public static DataTable Partition(this DataTable tbl, TextVector ColumnNames, NumVector RowIndices) Return subtable with selected columns and rows
public static TableViewer ViewTable_MultiThread(this DataTable Tbl, string Header = "Table Viewer") View DataTable in grid view (read-only), multi-thread
public static TableViewer ViewTable_SingleThread(this DataTable Tbl, string Header = "Table Viewer") View DataTable in grid view (read-only), single-thread
ExportTableToXMLfile(this DataTable Tbl, string Filename, string FileDir = "", bool IfAddTimeStamp = true) Save DataTable as an XML file
public static DataTable ImportTableFromXMLfile(this DataTable Tbl, string Filename, string FileDir = "") Read DataTable from an XML file
public static DataTable Sort(this DataTable Tbl, string SortStr) Sort table rows after given fields

Last edited Apr 12, 2013 at 8:35 PM by finaquant, version 8