谁能告诉我,为什么这段代码不能打开test.xls????<?
$exapp = new COM("Excel.application") or Die ("Did not connect");
$wk = "C:/web/test.xls";
$ws = "test";
$cs = "Daily SMS Usage";
$wkb = $exapp->application->Workbooks->Open($wk) or Die ("Did not open workbook");
$sheets = $wkb->Worksheets($ws) or Die("Did not open the sheet");
$exapp->Visible = 1;
$sheets->activate;
?>
$exapp = new COM("Excel.application") or Die ("Did not connect");
$wk = "C:/web/test.xls";
$ws = "test";
$cs = "Daily SMS Usage";
$wkb = $exapp->application->Workbooks->Open($wk) or Die ("Did not open workbook");
$sheets = $wkb->Worksheets($ws) or Die("Did not open the sheet");
$exapp->Visible = 1;
$sheets->activate;
?>
试过,就是上面一段代码,没有错误提示,只是直打印了一个结果:
Did not open the sheet不知是为何出此错。
昨天试验的结果是:
如果用这一句:
$exapp = new COM("Excel.application") or Die ("Did not connect");
则不能打开文件。
但是如果把这句话改成:
$exapp = new COM("Excel.sheet") or Die ("Did not connect");就可以打开文件了,但是,目前只能操作一次,无论是重启Apache还是在windows里logout,第二次都不能再进行这样的操作了。除非重启服务器。全部代码如下:
<pre>
<?php
$workbook = "C:\\web\\test.xls";
$sheet = "test";
$ex = new COM("Excel.sheet") or Die ("Did not connect");
$wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
$ex->Application->Visible = 1;
$sheets = $wkb->Worksheets($sheet); #Select the sheet
$sheets->activate; #Activate it
$cell = $sheets->Cells(3,1) ; #Select the cell (Row Column number)
$cell->activate; #Activate the cell
print "Old Value = {$cell->value}"; #Print the value of the cell:10000
$cell->value = 15000; #Change it to 15000
print "New value = {$cell->value}";#Print the new value=15000
$sheets->Calculate;
$cell = $sheets->Cells(13,5) ; #Select the cell (Row Column number)
$number = Number_format($cell->value);
print "New Total cost =$$number - was ,732 before.";
$ex->application->ActiveWorkbook->Close("False");
$ex->Quit();
unset($ex);
?>
</pre>
这段代码可以打开已经存在的excel文件,并且可以进行读写操作。
在MSDN中的代码,转换到PHP中,为何一点反应都没有呢???
再次强烈郁闷。
譬如下面一段代码。MSDN里的:
With Charts("Chart1")
.HasTitle = True
.ChartTitle.Text = "First Quarter Sales"
End With我转换成PHP的:#$co = $sheets->ChartObjects->Add(0, 0, 500, 400);
$co = $wkb->Charts->Add();
$co->HasTitle = True;
$co->ChartTitle->Text = "First Quarter Sales";请问有没有对这方面比较熟悉的,我的目的是要做一个chart,chart中series的数量,每个series的值以及其name都是动态从另外一个Sheet中取得的,请问如何用PHP语句实现?
我无论如何也不能把MSDN中的语句转换到PHP中来?再次郁闷