Home > Back-end >  BCB6 thrown open the EXCEL spreadsheet with OLE EAccessViolation anomalies
BCB6 thrown open the EXCEL spreadsheet with OLE EAccessViolation anomalies

Time:09-21

As shown in figure



Attach the code
if(! FileExists (path))
{
Form1 - & gt; Memo1 - & gt; Lines - & gt; Add (" Error: database file does not exist ");
return false;
}
CoInitialize (NULL);
Try
{
ExcelApp=the Variant: : CreateObject (" Excel. Application ");
ExcelApp. OlePropertyGet (" workbooks "). OleFunction (" open ", path);//run in this step throws an exception
//ExcelApp OlePropertySet (" Visible ", false);
}
The catch (... )
{
Form1 - & gt; Memo1 - & gt; Lines - & gt; Add (" Excel operation error, please make sure to install Office ");
return false;

}




WorkBook1=ExcelApp. OlePropertyGet (" ActiveWorkBook ");

WorkBook1. OlePropertyGet (" Sheets ", 1). OleProcedure (" Select ");
Sheet1=WorkBook1. OlePropertyGet (" ActiveSheet ");
  • Related