Click here to Skip to main content
11,709,220 members (72,635 online)
Click here to Skip to main content

Loading Excel data into a GridView

, 7 Oct 2011 CPOL 9.4K 1
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())
{
	//excelReader.GetInt32(0);
}
 
//6. Free resources (IExcelDataReader is IDisposable)
excelReader.Close();

License

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

Share

About the Author

No Biography provided

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    Rant Rant    Admin Admin   

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

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