Click here to Skip to main content
13,145,603 members (36,759 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 7 Oct 2011

Loading Excel data into a GridView

, 7 Oct 2011
Rate this:
Please Sign up or sign in to vote.
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);//1. Reading from a binary Excel file ('97-2003 format; *.xls)IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);//...//2. Reading from a OpenXml Excel file (2007 format;...
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
//2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
//3. DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = excelReader.AsDataSet();
//4. DataSet - Create column names from first row
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
//5. Data Reader methods
while (excelReader.Read())
//6. Free resources (IExcelDataReader is IDisposable)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

Generalits copy paste of "Alternative 1" link content.. Pin
kiran dangar6-Oct-11 21:08
memberkiran dangar6-Oct-11 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 7 Oct 2011
Article Copyright 2011 by genious Developer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid