Shaitan00 Posted November 5, 2005 Posted November 5, 2005 My goal is to create a .XLS file (Excel) without the need for the Excel COM Object (and corresponding office .dlls), so this is how I am trying to create my Table (worksheet), by treating it like any other Database. My connection string is as follows "provider=Microsoft.Jet.OLEDB.4.0; data source=" + sDB + "; Extended Properties=Excel 8.0;" (where sDB=ClientTaskTimer.xls) and the code I use is posted below: System.IO.File.Create("ClientTaskTimer.xls"); oDB = new objDB("ClientTaskTimer.xls"); oDB.Write("CREATE TABLE ClientTaskTimer ([CLIENTS] varchar, [ASSIGNMENTS] varchar)"); [/Code] oDB is a class that creates the Database connection (pass in the Database name, in this case the excel .xls file) and also reads/writes (Adapter/Command). Sadly this doesn't seem to work perfectly, specifically if the .XLS file already exists and was created BY Excel then my table (worksheet) is added perfectly and everyone is happy, HOWEVER given the code posted above (which is supposed to CREATE the Excel file AND Table - meaning it makes the Template for the Database if this is the first time you run the application) I keep getting the following ERROR MESSAGE: System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data. Is there something wrong with the way I am creating my Database File (Excel .xls file)? The only reason I am making it a .XLS is because a) I can't use a real DB b) a Text file is to nasty and c) it allows the users to open the excel file and view it seperatly Any help/hints would be greatly appreciated - or if you can propose another way to go about this problem...? Thanks Quote
FZelle Posted November 6, 2005 Posted November 6, 2005 First of all, close the newly opened file, and the message will disapear. Secondly, why don't you use XML? DataSet1.WriteXml() is easy to use. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.