Export data to Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
I am exporting data to Excel from my .net Application using ISAM(Jet). I
want to delete all record in the sheet before exporting. Since ISAM does not
support Delete Operation. I am trying to Delete the Sheet and then create new
sheet. The code executes successfully but The when i open the sheet it
contains the existing data.


for(i = 0;i<SchemaTable.Rows.Count;i++)
{//if schema is there then searches for the specific sheet
if(SchemaTable.Rows["TABLE_NAME"].ToString()==sheetName)
{
OleDbCommand ol1= new OleDbCommand("DROP TABLE " +
sheetName.Substring(0,sheetName.Length-1),conn);
ol1.ExecuteNonQuery();
break;
}
}
try
{
OleDbCommand ol = new OleDbCommand("create table [" +
sheetName.Substring(0,sheetName.Length-1) + "] (" + getExcelColumnNames(true)
+")",conn);
ol.ExecuteNonQuery();
}
catch(Exception e)

MessageBox.Show(e.Message,TitleText,MessageBoxButtons.OK,MessageBoxIcon.Information);
return false;
}
}
 
¤ Hello
¤ I am exporting data to Excel from my .net Application using ISAM(Jet). I
¤ want to delete all record in the sheet before exporting. Since ISAM does not
¤ support Delete Operation. I am trying to Delete the Sheet and then create new
¤ sheet. The code executes successfully but The when i open the sheet it
¤ contains the existing data.
¤
¤
¤ for(i = 0;i<SchemaTable.Rows.Count;i++)
¤ {//if schema is there then searches for the specific sheet
¤ if(SchemaTable.Rows["TABLE_NAME"].ToString()==sheetName)
¤ {
¤ OleDbCommand ol1= new OleDbCommand("DROP TABLE " +
¤ sheetName.Substring(0,sheetName.Length-1),conn);
¤ ol1.ExecuteNonQuery();
¤ break;
¤ }
¤ }
¤ try
¤ {
¤ OleDbCommand ol = new OleDbCommand("create table [" +
¤ sheetName.Substring(0,sheetName.Length-1) + "] (" + getExcelColumnNames(true)
¤ +")",conn);
¤ ol.ExecuteNonQuery();
¤ }
¤ catch(Exception e)
¤ {
¤ MessageBox.Show(e.Message,TitleText,MessageBoxButtons.OK,MessageBoxIcon.Information);
¤ return false;
¤ }
¤ }


You can't use data access methods to delete (or DROP) a Worksheet in a Workbook. The only method
that works is Excel automation.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top