Home  >  Article  >  Backend Development  >  How to export and generate word using php

How to export and generate word using php

PHP中文网
PHP中文网Original
2017-03-22 14:06:555679browse

The example in this article describes the method of exporting php to generate word. Share it with everyone for your reference, the details are as follows:

PHP export word

(1) First, preview the html page, instantiate the object, and define the data to be exported
(2) Click the download page and pass the value to the id (any value Both are acceptable, only for judgment), if the id has a value, output the buffer file and save it in word format.
(3) After clicking download, (if it is a picture, use the absolute path when saving it as word, so that it can be displayed normally in the saved word)
(4) Turn off the cache output

Word_con.php preview to be exported The html file

start();//定义要保存数据的开始
}
include('word_show.php');
 if(@$_GET[id]!='')
 {
   $word->save('word_c.doc');//定义要保存数据的结束,同时把数据保存到word中
 }
 if(@$_GET[id]=='')
 {
 //超链接中的x仅仅是为了传一个值,确认下载,没有其他的实际yi
 ?>
 

点击跳到下载页面

下载"; } ?>

Word_fun.php exports word-related functions

';
}
function save($path) //定义要保存数据的结束,同时把数据保存到word中  
//所要保存的数据必须限定在该类的start()和save()之间
{
print "";
$data=ob_get_contents(); //返回内部缓冲的内容 即把输出变成字符串
ob_end_clean(); //结束输出缓冲,清洁(擦除)输出缓冲区并关闭输出缓冲
$this->wirtetoword($path,$data);
}
function wirtetoword($fn,$data) //将数据已二进制的形式保存到word中
{
$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}
}
?>

Word_show.php to connect to the database and query related data

hahaahahha";
  echo $que['zf_content'];
 }
?>

I hope this article will be helpful to everyone in PHP programming.

Related articles:

php uses phpword to generate word documents

Generate word documents from web pages in the php program and provide downloadable example codes

Three ways to implement PHP to generate word documents

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn