一、用windows里面自带的com,然后用 php生成word文档。
<?php
$word= new COM("word.application") or die("Unable to create Word document");
print "Loaded Word, version {$word->Version}\n";
$word->Visible = 0;
$word->Documents->Add();
//设置边距
$word->Selection->pageSetup->LeftMargin = '3';
$word->Selection->pageSetup->RightMargin = '3';
//设置字体
$word->Selection->Font->Name = 'Helvetica';
//设置字号
$word->Selection->Font->Size = 8;
//设置颜色
$word->Selection->Font->ColorIndex= 13; //wdDarkRed = 13
//输出到文档
$word->Selection->TypeText("string string string string string string ");
$range = $word->ActiveDocument->Range(0, 0);
$table_t = $word->ActiveDocument->Tables->Add($range,3,4); //生成3行4列
$table_t->Cell(1, 2)->Range->InsertAfter('aaa'); //向第1行第2列插入aaa
//保存
//$word->Sections->Add(1);
$word->Documents[1]->SaveAs(dirname(__FILE__)."/create_test.doc");
//退出
$word->quit();
?>
二、用php类直接生成word文档
<?php
//生成word文档
// www.jbxue.com
class word
{
function start()
{
ob_start();
print’<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="’">http://www.w3.org/TR/REC-html40">’;
}
function save($path)
{
print "</html>";
$data = ob_get_contents();
ob_end_clean();
$this->wirtefile ($path,$data);
}
function wirtefile ($fn,$data)
{
$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}
}
/*-------word class End-------*/
$word=new word;
$word->start();
echo $cout;
$wordname="word/".time().".doc";
$word->save($wordname);//保存word并且结束.
?>
<?php
require_once("../../config/sys_config.php"); //配置文件
require_once("../../include/db_class.php");
header("Content-type: text/html; charset=$page_Code"); //页面编码
header("Content-Type:application/msword");
header("Content-Disposition:attachment;filename=".mb_convert_encoding("客户资料报表","GBK","$page_Code").".doc");
header("Pragma:no-cache");
header("Expires:0");
$usersId = intval( $_GET['uid'] ); //用户ID
?>
<html>
<meta http-equiv=Content-Type content="text/html; charset=<?php echo $page_Code; ?>">
<style media="print" type="text/css">
<!--
body {
margin-left: 0cm;
margin-top: 0cm;
margin-right: 0cm;
margin-bottom: 0cm;
}
-->
</style>
<body>
<table width="100%" style='border-collapse:collapse;'>
<tr>
<td width='24%' bgcolor='#CCCCCC' style='border:1px solid #000000;font-size:12px;'>客户名称</td>
<td width='13%' bgcolor='#CCCCCC' style='border:1px solid #000000;font-size:12px;'>电话号码</td>
<td width='32%' bgcolor="#CCCCCC" style='border:1px solid #000000;font-size:12px;'>客户地址</td>
<td width='11%' bgcolor="#CCCCCC" style='border:1px solid #000000;font-size:12px;'>添加日期</td>
<td width='20%' bgcolor="#CCCCCC" style='border:1px solid #000000;font-size:12px;'>客户备注备注</td>
</tr>
<?php
$sqlstr = "select * from clients where usersId=$usersId order by clientsId desc";
$rows = $db -> select($sqlstr);
$num = count($rows); //客户总数
for( $i = 0; $i < $num; $i++ )
{
?>
<tr>
<td style='border:1px solid #000000;font-size:12px;'><?php echo $rows[$i][clientsName]?></td>
<td style='border:1px solid #000000;font-size:12px;'><?php echo $rows[$i][clientsPhone]?></td>
<td style='border:1px solid #000000;font-size:12px;'><?php echo $rows[$i][clientsAddress]?></td>
<td style='border:1px solid #000000;font-size:12px;'><?php echo $rows[$i][clientsTime]?></td>
<td style='border:1px solid #000000;font-size:12px;'> </td>
</tr>
<?php
}
?>
</table>
</body>
</html>
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com