Click here to Skip to main content
15,943,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want read file Exel file, I done:
C#
static DataTable GetSheetData(string excelFile, int sheetindex){  
string sheetname = GetExcelSheetNames(excelFile)[sheetindex];  
string srcConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + @";Extended Properties=""Excel 8.0;HDR=YES;""";  
string srcQuery = "Select * from [" + sheetname + "]";  
OleDbConnection srcConn = new OleDbConnection(srcConnString);  
srcConn.Open();  
OleDbCommand objCmdSelect = new OleDbCommand(srcQuery, srcConn);  
DataSet ds = new DataSet();  
OleDbDataAdapter da = new OleDbDataAdapter(objCmdSelect);  
da.Fill(ds, sheetname);  
srcConn.Close();  
return ds.Tables[0];  
}  

If sheetname have blank charaters blanks, I can't read file. How can read the file when sheetname blank characters? Thanks
Posted
Updated 19-Sep-12 18:58pm
v2
Comments
Rockstar_ 20-Sep-12 0:13am    
Sheetname will always contains at least a character
violetqa 20-Sep-12 0:21am    
No, mean character blanks is space example: "Sheet Account"

1 solution

try:
string srcQuery = "Select * from [" + sheetname + "$]";
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900