Hi all,
Running php 4.3.1 on win NT box. Executing this php script from the command line. Trying to open .xls file via com write to it and close it. The code works fine, however...upon completion, I'm getting an Excel.exe application error.
<?php
//*************************************************
//
//
//*************************************************
//**** Begin customizable vars ****
$pathToReport = "C:\\Reports\\adhoc\\testing\\";
$pathToBak = "C:\\Reports\\adhoc\\testing\\bak\\";
$fileToSave = "testing2.xls";
$backup = "backup.xls";
//**** End customizable vars ****
//Set the workbook to use and its sheet.
$sheet = 1;
//Instantiate the spreadsheet component.
$excel = new COM("Excel.sheet") or Die ("Did not connect");
//Open the workbook that we want to use.
$book = $excel->application->Workbooks->Open($pathToReport.$fileToSave) or Die ("Did not open book");
//Create a copy of the workbook, so the original workbook will be preserved.
$excel->Application->ActiveWorkbook->SaveAs($pathToBak.$backup);
//$excel->Application->Visible = 1; //Uncomment to make Excel visible.
// Read and write to a cell in the new sheet
// We want to read the cell
$sheets = $book->Worksheets($sheet); //Select the sheet
$sheets->activate; //Activate it
$cell = $sheets->Cells(1,1) ; //Select the cell (Row Column number)
$cell->activate; //Activate the cell
$cell->value = 15000; //print to cell 15000
//Optionally, save the modified workbook
$excel->Application->ActiveWorkbook->SaveAs($pathToReport.$fileToSave);
//Close all workbooks without questioning
//$excel->application->ActiveWorkbook->Close("False");
//unset ($excel);
$book->Close(false);
unset($cell);
unset($sheets);
unset($book);
$excel->application->ActiveWorkbook->Close();
unset($excel);
?>
I have a feeling the error is coming from somewhere near where I'm trying to destroy the objects....but just can seem to isolate the problem.
Any suggestions?
Thanks.