Board index » cppbuilder » Forcfully close Excel
Michael
![]() CBuilder Developer |
Forcfully close Excel2006-10-10 10:54:40 PM cppbuilder16 Hi there I have a class that writes to an excel file, the only problem is that it will throw an exception when I wrtie to an excel file that is currently open. Is there anyway I can forcefully close the file. I have the following code: FileHandler::FileHandler(String filename) { fileXls = filename; /*Initialise File*/ XLApp = Variant::CreateObject("excel.application"); //open excel application XLApp.OlePropertySet("visible",false); //set application to invisible v0 = XLApp.OlePropertyGet("workbooks"); //get workbook v0.OleProcedure("Add"); //add one workbook v1 = v0.OlePropertyGet("Item",1); //select workbook number 1 v2 = v1.OlePropertyGet("WorkSheets"); //Get worksheet v2.OleFunction("Add"); // add one work sheet v3 = v2.OlePropertyGet("Item",1); //select worksheet number 1 v3.OlePropertySet("Name","Example"); //rename worksheet it to "example1? } FileHandler::~FileHandler() { //Close the work book v1.OleProcedure("Close"); //quite the excel application XLApp.OleProcedure("Quit"); //unassign variable XLApp=Unassigned; } void FileHandler::Write(double val,int row,int col) { char temp[10]; sprintf(temp,"%lf",val); /*Write val to row, col position in excel*/ v3.OlePropertyGet("Cells").OlePropertyGet("Item",row,col).OlePropertySet("Value",temp); //this will stop asking you where you want to save your excel file or not XLApp.OlePropertySet("DisplayAlerts",false); //save your excel file at "d" and name it as "case1.xls" XLApp.OlePropertyGet("Workbooks").OlePropertyGet("Item",1).OleProcedure("SaveAs","C:\\TEST1.xls"); } Any help would be greatly appreciated. Thanks Mike |