Jump to content

Excel COM code hangs on $Range->locked = true/false


mohitshar

Recommended Posts

I am trying to lock some cells in an excel file. The PHP code is shown below. 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 (Locked is printed as false).

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.