PHP导出word,CVS,PDF
2024-10-19 03:39:05
WORD:
<?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="http://www.w3.org/TR/REC-html40">
<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;
?>
CVS:
<?php
header("Content-Disposition: attachment; filename=邮寄地址.csv");
echo "姓名,性别,年龄,电话\n张三,男,23,15010125818";
?>
注:echo中的逗号是每个列的分割标识符,\n则是换行。
还有如下可参考:
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
PDF:
<?php
header("Content-type:application/pdf"); // 文件将被称为 downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'"); // PDF 源在 original.pdf 中
readfile("original.pdf");
?> <html>
<body> ...
...
最新文章
- 后缀.jar的是什么文件?
- struts2总结三:struts2配置文件struts.xml的简单总结
- [转]C++ DLL远程注入与卸载函数
- Titanium系列--我常用的Titanium的快捷键(持续更新中。。)
- URAL 1549 Another Japanese Puzzle(构造)
- PHP 错误与异常 笔记与总结(14 )记录和发送异常信息
- CSS的基本操作
- 基础面试题——Javascript
- debian下安装AMD驱动
- 工作流管理系统 jBPM
- 【Beta阶段】第七次scrum meeting
- linux route 路由设置小记
- P1451 求细胞数量
- Linux 目录结构和常用命令
- Vue 中 diff 算法后更新 DOM 的方法
- Python数据类型的内置函数之list(列表)
- vmware平台下两次网络不通的诡异事件
- gcc库链接
- Omi框架学习之旅 - 插件机制之omi-transform及原理说明
- ionic创建项目失败
热门文章
- bzoj 3275 最小割
- ZOJ 3623 Battle Ships DP
- Loadrunner问题:Monitor name :Windows Resources. Cannot create measurement Processor|% Processor Time|_Total on machine 192.168.0.1
- js ajax post 提交的时候后台接收不到参数,但是代码没有错,怎么回事
- Backup your Android without root or custom recovery -- adb backup
- DotNet_Performance_Tuning_ANTS_Performance_Profiler
- [Node.js]OS模块
- 安装openldap
- EasyUI相同的Tab只打开一个(即EasyUI方法的调用方法)
- FizzBuzzWhizz问题python解法