如何将HTML页面生成可下载的Word文档?
- 内容介绍
- 文章标签
- 相关推荐
本文共计199个文字,预计阅读时间需要1分钟。
python/*** @desc 生成Word文档并下载* @param $content 文档内容* @param $fileName 文件名称*/function downloadWord($content, $fileName='new_file.doc') { if (empty($content)) { return; } header('Cache-Control: no-cache, must-revalidate'); // 以下为生成Word文档的代码,具体实现取决于使用的库或方法 // ...}
/**
* @desc生成word文档并下载
* @param $content 文档内容
* @param string $fileName 文档名称
*/
function downloadWord($content, $fileName='new_file.doc'){
if(empty($content)){
return;
}
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$fileName");
$html = '<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="schemas.microsoft.com/office/2004/12/omml"
xmlns="www.w3.org/TR/REC-html40">';
$html .= '<head><meta charset="UTF-8" /></head>';
echo $html . '<body>'.$content .'</body></html>';
}
本文共计199个文字,预计阅读时间需要1分钟。
python/*** @desc 生成Word文档并下载* @param $content 文档内容* @param $fileName 文件名称*/function downloadWord($content, $fileName='new_file.doc') { if (empty($content)) { return; } header('Cache-Control: no-cache, must-revalidate'); // 以下为生成Word文档的代码,具体实现取决于使用的库或方法 // ...}
/**
* @desc生成word文档并下载
* @param $content 文档内容
* @param string $fileName 文档名称
*/
function downloadWord($content, $fileName='new_file.doc'){
if(empty($content)){
return;
}
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$fileName");
$html = '<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="schemas.microsoft.com/office/2004/12/omml"
xmlns="www.w3.org/TR/REC-html40">';
$html .= '<head><meta charset="UTF-8" /></head>';
echo $html . '<body>'.$content .'</body></html>';
}

