=波波日志 > PHP/apache/Perl > php学习--使用COM=
php学习--使用COM
示例代码点击这里下载
生成excel电子表格
使用word模板
生成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/apache/Perl 作者:波波 日期:2009-07-10 【评论:0】
暂时没有评论!
发表留言
百度赞助
同类热门博文
- ·IE里Cookie跨域不能..
- ·php隐形字符65279
- ·Apache NameVirtual..
- ·Apache2.2提示Canno..
- ·Cookie在IE浏览器跨..
- ·获取google的pr值
- ·php根据访问者ip地址..
- ·PHP“Cannot use ob..
博格Tag
- flash/flex/fcs/AIR(752)
- Asp.Net/C#/WCF(598)
- 操作系统及应用软件(376)
- JavaScript/Ajax(330)
- SQL及数据库(134)
- 黑客技术(115)
- Asp/VBScript(111)
- HTML/WML/CSS兼容/XML(102)
- PHP/apache/Perl(96)
- 网站排名及优化(92)
- 其他(75)
- showbo日志(66)
- lucene.net/分词技术(33)
- 计算机网络(26)
- 机械重工(26)
- C#设计模式(24)
- Google Maps开发(17)
- 日语学习(15)
- Canvas/VML/SVG(13)
- linux(11)
- 游戏开发(8)
- 正则表达式(5)
- Jsp/Java(4)
最新博文
- ·PHP socket套接字学..
- ·Warning Cannot sen..
- ·php与flash as3 soc..
- ·php socket套接字聊..
- ·php获取来源页面
- ·CentOS5.5配置Apach..
- ·wget使用详解
- ·curl使用详解
随机博文
