如何通过HTML生成可下载的Word文档?

更新于
2026-09-16 18:40:19
29阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计183个文字,预计阅读时间需要1分钟。

如何通过HTML生成可下载的Word文档?

python/*** 生成Word文档并下载* @param content 文档内容* @param fileName 文件名称,默认为'new_file.doc'*/function downloadWord($content, $fileName='new_file.doc') { if (empty($content)) { return; } header('Cache-Control: no-cache, must-revalidate');}

如何通过HTML生成可下载的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>';

}

本文共计183个文字,预计阅读时间需要1分钟。

如何通过HTML生成可下载的Word文档?

python/*** 生成Word文档并下载* @param content 文档内容* @param fileName 文件名称,默认为'new_file.doc'*/function downloadWord($content, $fileName='new_file.doc') { if (empty($content)) { return; } header('Cache-Control: no-cache, must-revalidate');}

如何通过HTML生成可下载的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>';

}