PHP --- Excel无法正确保存(COM)

时间:2013-11-19 15:22:25

标签: php sql excel com

我创建了这个clsExcel来处理我的excel文档。请不要推荐PHPExcel,因为我没有使用它。

它进入保存部分并挂起。在我的活动查看器中,它说我的临时文件已经存在..但我不明白为什么会这样?

Microsoft Excel 名为' C:\ WINDOWS \ Temp \ tmp5C2E.tmp'已存在于此位置。你想替换它吗? P1:100110 P2:14.0.7015.1000 P3:5f1w P4:

呼叫:

$input = "C:\\forms\\areview.xls";
$output =tempnam("C:\\WINDOWS\\Temp","tmp");
$Excel = new clsMSExcel;
$Excel->Open($input);
$Excel->WriteText($buffer, 1,1);
$Excel->WriteText($bufferT, 2,2);
$Excel->WriteText($buffer2, 3,3);
$Excel->SaveAs($output);
$Excel->Quit(); 
    set_time_limit(0);  
output_file($output, "areview.xls", '');

我的clsExcel.php

class clsMSExcel
   {
       var $handle;
       function clsMSExcel($Visible = false)
       {
       $this->handle = new COM("excel.application") or die("Unable to load excel");
       $this->handle->Visible = $Visible;
       }
 // Open existing document --------------
       function Open($File){$this->handle->Workbooks->Open($File) or Die ("Did not open");}
// Create new document ------------------
       function NewDocument(){$this->handle->Workbooks->Add();}
// Write text to active document --------
       function WriteText( $Text, $c1, $c2 ){$this->handle->ActiveSheet->Cells($c1,$c2)->Value = $text;}
// Number of documents open
       function DocumentCount(){return $this->handle->Workbooks->Count;}
// Save document as another file and/or format
       function SaveAs($File, $Format = 56 ){
       $this->handle->ActiveWorkbook->SaveAs($File, $Format);}
// Save active document
       function Save(){$this->handle->ActiveWorkbook->Save();}
// close active document.
       function Close(){$this->handle->ActiveWorkbook->Close();}
// Get excel version
       function GetVersion(){return $this->handle->Version;}
// get handle to excel
       function GetHandle(){return $this->handle;}
// Clean up instance with excel
       function Quit()
       {
       if( $this->handle )
       {
 // close excel
    try 
{
 $this->handle->Quit();
// free the object
 $this->handle->Release();
 $this->handle = null;
} catch ( Exception $e ) {}
   }
   }
   };
?>

0 个答案:

没有答案