Resources on the network:
C # reading ExcelCode:
View sourceprint?
01 |
String Strconn = "Provider = Microsoft. Jet. oledb.4.0; Data Source =" + Filepath + "; Extended properties = 'excel 8.0; HDR = no; IMEX = 1 ';" ; // Cannot be 11.0 |
02 |
Oledbconnection conn = New Oledbconnection (strconn ); |
04 |
String Strexcel = "Select * from [sheet1 $]" ; |
05 |
Oledbdataadapter da = New Oledbdataadapter (strexcel, strconn ); |
06 |
Dataset DS = New Dataset (); |
13 |
Throw New Exception ( "Failed to read Excel :" + Ex. Message ); |
If "installable isam is not found" is prompted, there are two solutions through Google:
1. connection string Problems
View sourceprint?
1 |
Extended properties = 'Excel 8.0; HDR = no; IMEX = 1' |
// HDR indicates whether to use the first row as the data or column name, HDR = No as the data, and HDR = yes as the column name; IMEX = 1 is used to read the hybrid type as the text type to avoid null values.
The left and right single quotes of the above sentence cannot be less
2. You only need to register an Excel isam.
Enter regsvr32 c: \ windows \ system32 \ msexcl40.dll in the "run" dialog box.
C # Read the Excel Code:
View sourceprint?
01 |
String Strconn = "Provider = Microsoft. Jet. oledb.4.0; Data Source =" + Filepath + "; Extended properties = 'excel 8.0; HDR = no; IMEX = 1 ';" ; // Cannot be 11.0 |
02 |
Oledbconnection conn = New Oledbconnection (strconn ); |
04 |
String Strexcel = "Select * from [sheet1 $]" ; |
05 |
Oledbdataadapter da = New Oledbdataadapter (strexcel, strconn ); |
06 |
Dataset DS = New Dataset (); |
13 |
Throw New Exception ( "Failed to read Excel :" + Ex. Message ); |
If "installable isam is not found" is prompted, there are two solutions through Google:
1. connection string Problems
View sourceprint?
1 |
Extended properties = 'Excel 8.0; HDR = no; IMEX = 1' |
// HDR indicates whether to use the first row as the data or column name, HDR = No as the data, and HDR = yes as the column name; IMEX = 1 is used to read the hybrid type as the text type to avoid null values.
The left and right single quotes of the above sentence cannot be less
2. You only need to register an Excel isam.
Enter regsvr32 c: \ windows \ system32 \ msexcl40.dll in the "run" dialog box.