1.如何在php中读取word的table和图片
<?
// 建立一个指向新COM组件的索引
$word = new COM("word.application") or die("Can't start Word!");
$word->Visible = 1; #打开一个新文档
$word->Documents->Add();
#写
$word->Selection->TypeText("This is my a test。..");
#存
$word->Documents[1]->SaveAs("D:/tanfanlin.doc"); //打开文档
$word->Documents->OPen("D:/tanfanlin.doc");
echo $word->ActiveDocument->content->Text;
//关闭 word
$word->Quit();?> table 需要转换输出
2.使用phpword 如何才能在一个表格中的某个单元格 插入多张图片
require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
//定义样式数组
$styleTable = array(
'borderSize'=>6,
'borderColor'=>'006699',
'cellMargin'=>80
);
$styleFirstRow = array(
'borderBottomSize'=>18,
'borderBottomColor'=>'0000ff',
'bgColor'=>'66bbff'
);
//定义单元格样式数组
$styleCell = array('valign'=>'center');
$styleCellBTLR = array('valign'=>'center','textDirection'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);
//定义第一行的字体
$fontStyle = array('bold'=>true,'align'=>'center');
//添加表格样式
$PHPWord->addTableStyle('myOwnTableStyle',$styleTable,$styleFirstRow);
//添加表格
$table = $section->addTable('myOwnTableStyle');
3.php 怎么实现打印 功能啊 直接打印html中的table 而且为word格式 table
你的打印是不是编程语言里面说的打印,例如basic语言的print语句,如果是的话,在PHP里面使用echo语句打印内容,例如:
echo '<table border=1><tr><td>1<td>2</table>';
如果你是希望程序运行后在打印机上打印输出内容,那可能比较复杂,而且不是PHP的强项,需要编写许多查找打印机的代码,简单的做法是把数据送我特殊设备,可以使用file_put_contents函数,例如:
file_put_contents('PRN:', 'print test');
4.如何将php转换成word
有可能你的附件就是图片格式的吧。
看下后缀名是什么呢 打不开附件 要先确定你的附件是什么类型的文件 比如 图片要用图片查看器才能打开 压缩文件要用winrar等解压缩软件才能打开 word文件要用OFFICE办公软件才能打开 不同的文件类型要用不同的软件的才能打开 所以要先看看下的附件是什么类型的 看后面的扩展名是什么 以此要断定是什么类型的文件 比如.mp3是音乐文件.jpg是图片文件等等 根据你的描述 应该是hi缺少打开你下的那种类型文件的软件 所以 你先看哈是啥子文件吧。
5.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');。
6.如何用php生成表格
具体代码如下:
<?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, '/');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>
PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。
它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,
执行效率比完全生成HTML标记的CGI要高许多;
PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。
7.php导出符合excel标准的表格,非PHPExcel
用PHPExcel,PHPExcel是相当强大的 MS Office Excel 文档生成类库。
你上它的官/网把程序包下/载下来,里面有 PHPExcel 的程序、还有30个实例程序和三个文档。看一下其中的开发文档你就会用了。
读取(这段在开发文档里有的,在13页):require_once '../Classes/PHPExcel/IOFactory.php';$objReader = PHPExcel_IOFactory::createReader('Excel2007');$objReader->setReadDataOnly(true);$objPHPExcel = $objReader->load("test.xlsx");$objWorksheet = $objPHPExcel->getActiveSheet();echo '
' . $cell->getValue() . ' | ' . "\n"; } echo '
转载请注明出处51数据库 » phpwordtable