private void btnImportExcelToGrid_Click(object sender,
System.EventArgs e)
{
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Book2.xls;" +
"Extended Properties=Excel 8.0;";
DataSet ds = new DataSet();
//You must use the $ after the object
//you reference in the spreadsheet
OleDbDataAdapter da = new OleDbDataAdapter
("SELECT * FROM [Sheet1$]", strConn);
//da.TableMappings.Add("Table", "ExcelTest");
da.Fill(ds);
DataGrid2.DataSource = ds.Tables[0].DefaultView;
DataGrid2.DataBind();
}
Note: If you want to give client upload facility, than first upload the file to the server. Next call the excel file from the following server location. Reference: http://www.dotnetspider.com/kb/Article361.aspx
4 comments:
Hi,
Here you can find the fast and easy way to import or export DataGrid to XLS, XLSX, HTML or CSV files by using GemBox.Spreadsheet .NET component:
http://www.gemboxsoftware.com/LDataGrid.htm
Here you can find free version of the component that you can use even in commercial applications:
http://www.gemboxsoftware.com/GBSpreadsheetFree.htm
Mario
I saw the component and have limitation as below
Maximum number of rows per sheet is 150.
Maximum number of sheets per workbook is 5.
Hi,
I want to import the excel which has 6 tabs.i want to import the data into 6 different gridviews. Each tab contains more than 1000 records. without affecting the performance how to achieve this?
Please help me.
Thanks,
Ambu
Thanks
I've been searching such a easy code for a long time
Post a Comment