1. Purpose: To read a large amount of data in an Excel file and display it on the page:
Protected void page_load (Object sender, eventargs E)
{
// Address of the Excel file
String xlspath = server. mappath ("app_data/aa.xls ");
// Link character
String connstr = "provider = Microsoft. Jet. oledb.4.0;" + "extended properties = Excel 8.0;" + "Data Source =" + xlspath;
// Query statement. sheet1 specifies the sheet.
String SQL = "select * from [sheet1 $ A1: m30]";
Dataset DS = new dataset ();
// Query data
Oledbdataadapter da = new oledbdataadapter (SQL, connstr );
// Fill in Dataset
Da. Fill (DS );
// Output, bind data
Gridview1.datasource = Ds. Tables [0];
Gridview1.databind ();
}
Note:
The valid Excel version used for the extended properties value.
For Microsoft Excel 8.0 ( 97 ), 9.0 ( 2000 ) And 10.0 ( 2002 ) Workbook, use Excel 8.0 .
For Microsoft Excel 5.0 And 7.0 ( 95 ) Workbook, use Excel 5.0 .
For Microsoft Excel 4.0 Workbook, use Excel 4.0 .
For Microsoft Excel 3.0 Workbook, use Excel 3.0 .
This article reference: Xiaofeng residual month blog, URL: http://zt.cnblogs.com/page/42229/