用户登录
用户注册

分享至

php导出带样式的word

  • 作者: 疯狂小马一
  • 来源: 51数据库
  • 2020-04-21

1.php导出word和pdf文件

<?php

header("Cache-Control: no-cache, must-revalidate");

header("Pragma: no-cache");

//有了这些,可以把带html标签的html源码导入到word里,并且可以保持html的样式。

/*

<STYLE>

BR.page { page-break-after: always }

</STYLE>

在<head>;部分加这个是为了实现打印的时候分页

*/

$wordStr = '<html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:w="urn:schemas-microsoft-com:office:word"

xmlns="40">

<head>

<STYLE>

BR.page { page-break-after: always }

</STYLE>

</head><body>';

$wordStr = "<b>hello</b><p>this is html code</p>";

$wordStr .= '</body></html>';

//防止导出乱码

$file = iconv("utf-8", "GBK", $filename);

header("Content-Type: application/doc");

header("Content-Disposition: attachment; filename=" . $file . ".doc");

echo $wordStr;

?>

<?php

header("Content-type:application/pdf");

// 文件将被称为 downloaded.pdf

header("Content-Disposition:attachment;filename='downloaded.pdf'");

// PDF 源在 original.pdf 中

readfile("original.pdf");

?>

2.php怎么导出带样式的excel

/*** 导出文件* @return string*/public function export(){$file_name = "成绩单-".date("Y-m-d H:i:s",time());$file_suffix = "xls";header("Content-Type: application/vnd.ms-excel");header("Content-Disposition: attachment; filename=$file_name.$file_suffix");//根据业务,自己进行模板赋值。

$this->display();}。

3.如何将PHP网页导出为Word文件

ob_start();

header("Content-type:application/octet-stream");

header("Accept-Ranges:bytes");

header("Content-type:application/vnd.ms-excel");

header("Content-Disposition:attachment;filename=UserInfomation(目标文件名).doc");

//内容打印位置

print_r;

ob_end_flush();

4.你知道如何将PHP网页上的数据导出到word文档里面么

如果没有图片要导出的话,可以使用以下简单方式。

<?php

header("Content-type:application/vnd.ms-word");

header("Content-Disposition:filename=zgfun.doc");

echo "要导出的内容一。\r\n";

echo "要导出的第二行。";

?>

=============

如果要导出带图片的,则需要使用把网页保存为mht的格式下载。word可以直接打开。

转载请注明出处51数据库 » php导出带样式的word

软件
前端设计
程序设计
Java相关