Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
C# - Excel Data Reader Library - Convert Excel (XLSX or XLS) to CSV
* @Author: Munawwar
* Filename: ExcelDataReader.cs
* */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel;
using System.Data;
using System.IO;
* Dependency : Excel Data Reader from
* You must add the references to the Dlls (downloaded from the link above) with Visual Studio.
namespace ExcelDataReaderTest
class ExcelDataReader
static void Main(string[] args)
//Reading from a binary Excel file ('97-2003 format; *.xls)
//IExcelDataReader excelReader2003 = ExcelReaderFactory.CreateBinaryReader(stream);
//Reading from a OpenXml Excel file (2007 format; *.xlsx)
FileStream stream = new FileStream("../../myxlsx/sample.xlsx", FileMode.Open);
IExcelDataReader excelReader2007 = ExcelReaderFactory.CreateOpenXmlReader(stream);
//DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = excelReader2007.AsDataSet();
//Data Reader methods
foreach (DataTable table in result.Tables)
for (int i = 0; i < table.Rows.Count; i++)
for (int j = 0; j < table.Columns.Count; j++)
Console.Write("\"" + table.Rows[i].ItemArray[j] + "\";");
//Free resources (IExcelDataReader is IDisposable)

This comment has been minimized.

Copy link

clintmannar commented Mar 21, 2014


This comment has been minimized.

Copy link
Owner Author

Munawwar commented Apr 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.