php学习--使用COM
示例代码点击这里下载
生成excel电子表格
使用word模板
原创文章,转载请注明出处:php学习--使用COM
生成excel电子表格
+展开
-PHP
<?php
include_once("guid.php");
$ex=new COM("Excel.sheet") or die("Can't not open excel!");
//$ex->Application->Visible=1;
$wkb=$ex->application->workbooks->add();
$sheet=1;
excel_write_cell($wkb,$sheet,"A4","Hello,World!");
$exFileName=realpath(".")."\\".getGuid().".xls";
$wkb->SaveAs($exFileName);
$wkb->close();
$ex->application->Quit();
$ex=null;
function excel_write_cell($wkb,$sheet,$c,$v){
$sheets=$wkb->worksheets($sheet);
$sheets->activate;
$selcell=$sheets->Range($c);
$selcell->activate;
$selcell->value=$v;
}
function excel_read_cell($wkb,$sheet,$c){
$sheets=$wkb->worksheets($sheet);
$sheets->activate;
$selcell=$sheets->Range($c);
$selcell->activate;
return $selcell->value;
}
?>
include_once("guid.php");
$ex=new COM("Excel.sheet") or die("Can't not open excel!");
//$ex->Application->Visible=1;
$wkb=$ex->application->workbooks->add();
$sheet=1;
excel_write_cell($wkb,$sheet,"A4","Hello,World!");
$exFileName=realpath(".")."\\".getGuid().".xls";
$wkb->SaveAs($exFileName);
$wkb->close();
$ex->application->Quit();
$ex=null;
function excel_write_cell($wkb,$sheet,$c,$v){
$sheets=$wkb->worksheets($sheet);
$sheets->activate;
$selcell=$sheets->Range($c);
$selcell->activate;
$selcell->value=$v;
}
function excel_read_cell($wkb,$sheet,$c){
$sheets=$wkb->worksheets($sheet);
$sheets->activate;
$selcell=$sheets->Range($c);
$selcell->activate;
return $selcell->value;
}
?>
使用word模板
+展开
-PHP
<?php
include_once("guid.php");
$tmpdoc=realpath("temple.doc");
$customerinfo="Info Wyle COyote 123 Abc Ave. LooneyTune,USA 99999";
$deliverynum="00001";
$ordernum="12345";
$custnum="WB-beep";
$shipdate="11 Sep 2001";
$orderdate="11 Sep 2001";
$shipvia="UPS Ground";
$item[1]="SK-000-05";
$desc[1]="Acme Plcket Rocket";
$quantity[1]="2";
$cost[1]="$5.00";
$subtot[1]="$10.00";
$total="$10.00";
$word=new COM("word.application") or die("Can't not start ms word!");
print "loaded word version {$word->Version}\n<br/>";
//$word->visible=1;
$word->Documents->open($tmpdoc);
$word->Application->Run("BkmkCustomer");
$word->Selection->TypeText($customerinfo);
$word->Application->Run("BkmkDelivery");
$word->Selection->TypeText($deliverynum);
$word->Application->Run("NextCell");
$word->Selection->TypeText($shipdate);
$word->Application->Run("NextCell");
$word->Selection->TypeText($shipvia);
$word->Application->Run("NextCell");
$word->Selection->TypeText($orderdate);
$word->Application->Run("NextCell");
$word->Selection->TypeText($custnum);
$word->Application->Run("NextCell");
$word->Selection->TypeText($ordernum);
//$word->Application->Run("NextCell");
$word->Application->Run("BkmkItem");
$word->Selection->TypeText($item[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($desc[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($quantity[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($cost[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($subtot[1]);
$word->Application->Run("BkmkTOtal");
$word->Selection->TypeText($total);
/*
//打印doc的代码
$word->Application.Run("invoiceprint");//运行打印的doc宏
$word->Application->ActiveDocument->Saved=true;//保存
while($word->Application.BackgroundPrintingStatus>0)sleep)(1);//等待退出*/
//下面是另存为的代码
$docFileName=realpath(".")."\\".getGuid().".doc";
$word->ActiveDocument->SaveAs($docFileName);
$word->quit();
//$word->Release();
$word=null;
//echo "生成doc完成!";
?>
include_once("guid.php");
$tmpdoc=realpath("temple.doc");
$customerinfo="Info Wyle COyote 123 Abc Ave. LooneyTune,USA 99999";
$deliverynum="00001";
$ordernum="12345";
$custnum="WB-beep";
$shipdate="11 Sep 2001";
$orderdate="11 Sep 2001";
$shipvia="UPS Ground";
$item[1]="SK-000-05";
$desc[1]="Acme Plcket Rocket";
$quantity[1]="2";
$cost[1]="$5.00";
$subtot[1]="$10.00";
$total="$10.00";
$word=new COM("word.application") or die("Can't not start ms word!");
print "loaded word version {$word->Version}\n<br/>";
//$word->visible=1;
$word->Documents->open($tmpdoc);
$word->Application->Run("BkmkCustomer");
$word->Selection->TypeText($customerinfo);
$word->Application->Run("BkmkDelivery");
$word->Selection->TypeText($deliverynum);
$word->Application->Run("NextCell");
$word->Selection->TypeText($shipdate);
$word->Application->Run("NextCell");
$word->Selection->TypeText($shipvia);
$word->Application->Run("NextCell");
$word->Selection->TypeText($orderdate);
$word->Application->Run("NextCell");
$word->Selection->TypeText($custnum);
$word->Application->Run("NextCell");
$word->Selection->TypeText($ordernum);
//$word->Application->Run("NextCell");
$word->Application->Run("BkmkItem");
$word->Selection->TypeText($item[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($desc[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($quantity[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($cost[1]);
$word->Application->Run("NextCell");
$word->Selection->TypeText($subtot[1]);
$word->Application->Run("BkmkTOtal");
$word->Selection->TypeText($total);
/*
//打印doc的代码
$word->Application.Run("invoiceprint");//运行打印的doc宏
$word->Application->ActiveDocument->Saved=true;//保存
while($word->Application.BackgroundPrintingStatus>0)sleep)(1);//等待退出*/
//下面是另存为的代码
$docFileName=realpath(".")."\\".getGuid().".doc";
$word->ActiveDocument->SaveAs($docFileName);
$word->quit();
//$word->Release();
$word=null;
//echo "生成doc完成!";
?>
加支付宝好友偷能量挖...
原创文章,转载请注明出处:php学习--使用COM