Jump to content

Manipulating EXCEL Files using PHP COM - statement hangs script


mohitshar

Recommended Posts

I am using the PHP COM API to create an EXCEL file and then lock its cells. But the lock operation simply hangs the script.

The PHP code is shown below. When I request this script from a browser, the process EXCEL.EXE appears in the Windows task manager under the User 'SYSTEM'. But the script doesn't reach its end.

It seems that the script doesn't come out of the statement '$test->locked = False;'. After I close EXCEL.EXE process from task manager, the script exits and prints the right outputs (The value of the attribute 'Locked' is printed as false, which is what was requested).

Any ideas why the script hangs at '$test->locked = False;'?

 

Thanks,

Mohit Sharma

 

<?php

$filename = "c:/test2.xls";

$sheet1 = 1;

$excel_app = new COM("Excel.application") or Die ("Did not connect");

$excel_app->visible = 1; //Doesn't make visible

print ";;;$excel_app->visible\n"; //Prints null

print "Application name: {$excel_app->Application->value}\n";

print "Loaded version: {$excel_app->Application->version}\n";

$Workbook = $excel_app->Workbooks->Open("$filename",null,false,2);

$Worksheet = $Workbook->Worksheets($sheet1);

$Worksheet->activate;

$test = $Worksheet->Range("A1:IV65536");

$test->activate;

print "Before // $test->Locked\n";  //Prints 1

try {

  $test->locked = False;

  print "// After test->Locked\n";

} catch (Exception $e) {

  echo 'Caught exception: ', $e->getMessage(), ', Code: ', $e->code, "\n";

}

print "// $test->Locked\n";  //Prints false after closing EXCEL.EXE from task manager

var_dump( $test->Locked);

#To close all instances of excel:

$Workbook->Close();

unset($Worksheet);

unset($Workbook);

$excel_app->Quit();

unset($excel_app);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.