tags:

views:

28

answers:

2

HI! all I am creating .xls spreadsheet file using following code

using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\temp.xls;Extended Properties='Excel 8.0;HDR=Yes'"))
{
    conn.Open();
    OleDbCommand cmd = new OleDbCommand("CREATE TABLE [NewSheet] ([Column1] string, [Column2] string)", conn);
    cmd.ExecuteNonQuery();
}

but i am getting an exception at cmd.ExecuteNonQuery();

Exception is: Cannot modify the design of table 'NewSheet'. It is in a read-only database.

Please help me to resolve this

Thank You

+1  A: 

You need to add readonly= false to your connection string, see:

http://stackoverflow.com/questions/57987/writing-into-excel-file-with-oledb

Shiraz Bhaiji
Thank you so much.I am getting following Exception at: conn.open();Exception is: "Could not find installable ISAM."Please help
vamshi
A: 

SpreadsheetGear for .NET will let you open, modify and save Excel workbooks, has no limits on the structure of a workbook, and does not rely on OLEDB or anything else (other than .NET 2.0+).

You can see live samples here and download the free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson