1.可以把每一页转成图片,用flash显示,好多的在线阅读器好像都是这样做的(猜的,不一定是,呵呵)
2.参考一下这个:http://hi.baidu.com/bamfound/blog/item/388ebd266785b61a8a82a1cb.html
高分php word
这个实现不了,只能上传的时候直接上传有图片的word,这样才能下载有图片的。要做的话,也只能让下载一个压缩文件,包括文字和图片,让用户自己插入到word里面。你这应该是上传文字,然后下载成word,不需要图片吧?
那我想做一个word 标题不行么 ?
标题啊,这个可以啊,在$body = $row['body']这里,改成
$body = $row['title']."\r\n".$row['body']
就行了。
php怎样转换成word
//注意:要将PHPWord\PHPWord\Template.php中的setValue方法下的编码改成$replace = iconv('gbk', 'utf-8',$replace);其他的文件也要改成这种样式的。否则出现中文乱码。
require_once '../libs/PHPWord/PHPWord.php';
require_once '../libs/PHPWord/PHPWord/IOFactory.php';
require_once '../../config.php';
// require_once '../common/conn.php';
// New Word Document
$PHPWord = new PHPWord();
/**********文本格式的word text.php************/
// New portrait section
//逗号 分割字符串
$arr = $_REQUEST['arr'];
$a = explode(',',$arr);
//echo $arr;
date_default_timezone_set("Asia/Shanghai");//设置一个时区
$tm=date('Y-m-d H:i:s');
//exit($tm);
/**********前多日雨量*********/
if(in_array('1', $a, TRUE)){
$section = $PHPWord->createSection();
$PHPWord->addFontStyle('rStyle', array('bold'=>false, 'italic'=>false, 'size'=>16));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100));
$c = "前三日雨量报表";
$section->addText($c, 'rStyle', 'pStyle');
$styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80);
$styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF');
// Define cell style arrays
$styleCell = array('valign'=>'center');
// Define font style for first row
$fontStyle = array('bold'=>true, 'align'=>'center');
//设置标题
$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100));
// Add table style
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
// Add table
$table = $section->addTable('myOwnTableStyle');
// Add row设置行高
$table->addRow(500);
$table->addCell(2300, $styleCell)->addText('站码', $fontStyle);
$table->addCell(2300, $styleCell)->addText('站名', $fontStyle);
$table->addCell(2300, $styleCell)->addText('雨量', $fontStyle);
$table->addCell(2300, $styleCell)->addText('水文站监测类型', $fontStyle);
$conn = mssql_connect($config['mssql']['host'],$config['mssql']['user'],$config['mssql']['password']);
mssql_select_db($config['mssql']['dbname'],$conn);
$stm = date('Y-m-d H:i:s',strtotime('-3 days'));
$sql = "EXEC HNOW05_GETPPSPACE '','','".$stm."',1,1";
$res=mssql_query($sql);
while($arr = mssql_fetch_array($res)){
//echo $arr["STCD"]."
";
$table->addRow();
$table->addCell(2300)->addText($arr["STCD"]);
$table->addCell(2300)->addText($arr["STNM"]);
$table->addCell(2300)->addText($arr["P"]);
if($arr["STTP"] == 'MM'){
$table->addCell(2300)->addText('气象站');
}else if($arr["STTP"] == 'BB'){
$table->addCell(2300)->addText('蒸发站');
}else if($arr["STTP"] == 'DD'){
$table->addCell(2300)->addText('堰闸水文站');
}else if($arr["STTP"] == 'TT'){
$table->addCell(2300)->addText('落潮位站');
}else if($arr["STTP"] == 'DP'){
$table->addCell(2300)->addText('泵站');
}else if($arr["STTP"] == 'SS'){
$table->addCell(2300)->addText('墒情站');
}else if($arr["STTP"] == 'PP'){
$table->addCell(2300)->addText('雨量站');
}else if($arr["STTP"] == 'ZZ'){
$table->addCell(2300)->addText('河道水位水文站');
}else if($arr["STTP"] == 'RR'){
$table->addCell(2300)->addText('水库水文站');
}else if($arr["STTP"] == 'ZG'){
$table->addCell(2300)->addText('地下水站');
}else if($arr["STTP"] == 'ZB'){
$table->addCell(2300)->addText('分洪水位站');
}
}
$section->addTextBreak(2);
}else{
}
/******地质灾害*******/
if(in_array('3', $a, TRUE)){
$section = $PHPWord->createSection();
$PHPWord->addFontStyle('rStyle', array('bold'=>false, 'italic'=>false, 'size'=>16));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100));
$c = "地质灾害";
$section->addText($c, 'rStyle', 'pStyle');
$content="根据市气象局未来24小时降雨预报和市水利局实时降雨数据,市国土资源局进行了地质灾害预报,请有关部门关注
实时预警信息,做好地质灾害防范工作";
$section->addText($content);
// Add image elements
$section->addImage("images/image001.jpg", array('width'=>600, 'height'=>480, 'align'=>'center'));
}else{
}
// Save File
$fileName = "word报表".date("YmdHis");
header("Content-type: application/vnd.ms-word");
header("Content-Disposition:attachment;filename=".$fileName.".docx");
header('Cache-Control: max-age=0');
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');
php如何按照word 中的格式读取出来
如果你的服务端是windows的就比较好办,com组件可以直接使用的,搜索一下就有了,如果是linux就比较麻烦了。更多
我知道通过com(word.application)组件啊,但只能读取文字
不能读取图片,表格,还有文字格式
因为我没有在PHP里面实际操作过word文档,只是以前用ASP的时候用过,图片在里面是以字符串的形式存储的,这样的话imagecreatefromstring这个函数可以帮上你的忙的。
大歌,PHP与asp有很大的区别,不能用asp原理来……,再说asp更兼容word
用php 读取word 文档内容 比如:word文档为试题等等
这个是通过调用com组件的方式操作word的
<?
// 建立一个指向新COM组件的索引
$word = new COM("word.application") or die("Can't start Word!");
// 显示目前正在使用的Word的版本号
//echo “Loading Word, v. {$word->Version}<br>”;
// 把它的可见性设置为0(假),如果要使它在最前端打开,使用1(真)
// to open the application in the forefront, use 1 (true)
//$word->Visible = 0;
//打?一个文档
$word->Documents->OPen("d:\myweb\muban.doc");
//读取文档内容
$test= $word->ActiveDocument->content->Text;
echo $test;
echo "<br>";
//将文档中需要换的变量更换一下
$test=str_replace("<{变量}>","这是变量",$test);
echo $test;
$word->Documents->Add();
// 在新文档中添加文字
$word->Selection->TypeText("$test");
//把文档保存在目录中
$word->Documents[1]->SaveAs("d:/myweb/comtest.doc");
// 关闭与COM组件之间的连接
$word->Quit();
?>
还有其他的方法吗
还有还有
可以下载 antiword 要安装windows版或者是linux版自己选
然后用php调用,就可以操作word了
怎样用PHP读取一个word文档内容并在浏览器中显示出来?
传说中的phpword根本就不能读word文件,只能写,写完后可保存word,pdf.html等格式,网上一大把教程,都对读取避而不谈,都是一知半解粘贴过来骗积分的,就连官网上的手册也没有读的内容,想预览word,老老实实的在服务器上装插件吧。。。
php如何读取WORD文档
<?php
header("Content-type: application/msword");
readfile("test.doc");
?>
必须客户端装office,支持在线浏览 不知道你想干什么
php导出word 问题 急,在线等。。
<?PHP
$sql="select * from product";
$query=mysql_query($sql);
$i=0; while($row=mysql_fetch_row($query))
{
$sql2="select c_namecn from company where cid='$row[5]'";
$query2=mysql_query($sql2);
$row2=mysql_fetch_row($query2);
$i++;
$cout.=$i."";
$cout.=$row[6]."<br>";
$cout.="<b>所属公司</b>:";
$cout.=$row2[0]."<br>";
$cout.="<b>分类信息</b>:";
$cout.=$row[1]."--".$row[2]."--".$row[3]."--".$row[4]."<br>";
$cout.="<b>产品标准号</b>:".$row[7]."<br>";
$cout.="<b>产品净含量</b>:".$row[8]."<br>";
$cout.="<b>产地</b>:".$row[18]."<br>";
$cout.="<b>上架时间</b>:".$row[16]."<br>";
$cout.="<b>下架时间</b>:".$row[17]."<br>";
$cout.="---------------------------------<br>";
}//while
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.doc";
$word->save($wordname);//保存word并且结束.
?>
<div align="center"><a href="<?php echo $wordname ; ?>" target=_blank class="unnamed1">试卷已经生成,请点击这里查看</a>
</div>
转载请注明出处51数据库 » php写word php操作word