code:
Excel is a software in Microsoft's Office Kit, which is primarily used to process spreadsheets. Excel is welcomed by the majority of office staff with the advantages of friendly interface, and the rapid processing of data. So many documents are saved in Excel. For program designers, in programming, we tend to access the Excel file to get the data. However, because the Excel file is not a standard database, it is more difficult to use the program language to access him. ASP.NET is a product that Microsoft's highly recommended product, as an important part of the .NET Framework framework, which is mainly used for web design. The new design concept, powerful features make ASP.NET is being welcomed by more and more programming staff. It is also the powerful function of ASP.NET to make access to Excel documents a relatively simple matter. Below, an example is specifically illustrated how the ASP.NET accesses the Excel document. I. Program Design and Operation Environment (1) .windows 2000 Professional (2) .. Net Framework SDK Beta 2 (3). Microsoft Access Data Component 2.6 (MADC2.6) II. Specific Design Idea (1). Get Accessing the Excel file name (2). Read the contents of the Excel file (3). Displayed with the DataGrid format to specify some key steps. Third. Key Steps (1) for programming. For convenience, we assume the Excel file in the root directory of the C drive, name Test.xls. (2). In order to read the Excel file, we must understand a namespace - System.Data.OleDb. Three objects in System.Data.OleDB are OLEDBConnection, OLEDBCommand, OLEDBDataAdapter. We are accessing the Excel file by them. I> OLEDBConnection objects are mainly to provide a connection method. II> OLEDBCommand object provides specific operation methods for the target. The III> OLEDBDataAdapter object is the return data set after different operations of the object. In order to read the Test.xls of the C disk, you can do just the following statement: DIM myoledbconnection as oledbconnection = new oledbconnection ("provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: test.xls;" & _ "Extended Properties =" "Excel 8.0;" "") Dim myoledbcommand as oledbcommand = new oledbcommand ("Select * from [sheet1 $], myoledbconnection" If you want to read the contents of Sheet2, turn the Sheet1 $ to Sheet2 $ DIM MyData as oledbdataadapter = new oledbdataadapter (myoledbcommand) (3) After reading the contents of the Excel file, you have to display him with DataGrid. For display, use another namespace --system.data. He has an object Dataset, he can make data to DataGrid to display data in DataGrid. At this time, the data set read is not expressed in the object Dataset, which requires a conversion, so that the OLEDBDataAdapter object provides a method -fill, which can be converted.