C# read of xls file works on Vista home premium but not XP Pro, Vista Business or 2003 server. [modified]
-
These are the relevent lines from the code. The same file is being opened, the problem is that the program can't find the sheet when running under XPPRo, 2003 server, or Vista Business. All computers are up to date with the latest .net installed, all have Excel 2003 with current updates. Any ideas? string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); All Systems have Excel 2003 SP3 I get an error message on the failures: System.Data.OleDbException: The Microsoft Jet database engine could not find the object 'Sheet1$'
modified on Tuesday, February 17, 2009 12:14 PM
-
These are the relevent lines from the code. The same file is being opened, the problem is that the program can't find the sheet when running under XPPRo, 2003 server, or Vista Business. All computers are up to date with the latest .net installed, all have Excel 2003 with current updates. Any ideas? string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); All Systems have Excel 2003 SP3 I get an error message on the failures: System.Data.OleDbException: The Microsoft Jet database engine could not find the object 'Sheet1$'
modified on Tuesday, February 17, 2009 12:14 PM
Try using this as a connection string instead "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0;HDR=Yes;IMEX=1'"; I am going with the presumption that "filename" is an actual path and "Sheet1" does exist in all cases.... butyou know what they say about presumptions ;)
-
Try using this as a connection string instead "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0;HDR=Yes;IMEX=1'"; I am going with the presumption that "filename" is an actual path and "Sheet1" does exist in all cases.... butyou know what they say about presumptions ;)
You are correct. Filename is a variable holding the full path of the actual file, and sheet1 does exist in all cases, as in each instance, I have copied the file from one to another. What is the "IMEX=1" all about?
-
You are correct. Filename is a variable holding the full path of the actual file, and sheet1 does exist in all cases, as in each instance, I have copied the file from one to another. What is the "IMEX=1" all about?
Darn! Still no good. It makes no sense to me. Why fine on one but not on others? I used to say that I liked programming because of the instant gratification when you compile an app and it works, but this is an example of the dark counterpoint to that. Instant frustration.
-
Darn! Still no good. It makes no sense to me. Why fine on one but not on others? I used to say that I liked programming because of the instant gratification when you compile an app and it works, but this is an example of the dark counterpoint to that. Instant frustration.
HDR=Yes; Indicates that there are header rows in the sheet, and IMEX=1; 0 Export mode, 1 Import mode, 2 Linked mode, I run Imports from excel in 98/XP/Vista with that connection and its all good. How are you defining your path ie:Filename??
-
HDR=Yes; Indicates that there are header rows in the sheet, and IMEX=1; 0 Export mode, 1 Import mode, 2 Linked mode, I run Imports from excel in 98/XP/Vista with that connection and its all good. How are you defining your path ie:Filename??
This is all the relevant code. I just don't get why it would work for the one system but not the others. string filename = "C:\\Program files\\Daily_Totals_By_Employee.xls"; string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0'"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); con.Close();
-
This is all the relevant code. I just don't get why it would work for the one system but not the others. string filename = "C:\\Program files\\Daily_Totals_By_Employee.xls"; string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0'"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); con.Close();
I would try to put the file in a location like "C:\\Myfolder" just to test eliminate the "Program files" directory and see what happens, also punch in the path manually Data Source= C:\Myfolder\Daily_Totals_By_Employee.xls See if any of those work...sorry I can't be any more specific...
-
I would try to put the file in a location like "C:\\Myfolder" just to test eliminate the "Program files" directory and see what happens, also punch in the path manually Data Source= C:\Myfolder\Daily_Totals_By_Employee.xls See if any of those work...sorry I can't be any more specific...
I just tried the path suggestion. I changed the path to "C:\\csharpdata\\Daily_Totals_By_Employee.xls". No change. At the risk of being obtuse, I don't understand how permissions could be the problem. I'm not saying you're all wrong, just that I don't understand it. The file is being opened: wouldn't a permissions issue prevent that? The program opens the file then fails to find the sheet.