在日常办公或开发中,有时需要将网页(HTML)内容保存为 Word 文档(.doc 或 .docx)格式。本文将介绍几种简单有效的方法,适用于普通用户和开发者。
这是最简单的方式,适合临时保存网页内容:
Ctrl + S);.doc;适用于内容不多的页面:
Ctrl + C);Ctrl + V);推荐使用专业工具实现高质量转换:
使用前端库如 html-docx-js 或原生 Blob 方式:
<script>
function htmlToWord() {
const html = document.documentElement.outerHTML;
const blob = new Blob(['<html xmlns:o="urn:schemas-microsoft-com:office:office">' +
'<head><meta charset="utf-8"></head>' + html + '</html>'],
{ type: 'application/msword' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'document.doc';
a.click();
}
</script>
⚠️ 注意:此方法生成的是兼容 Word 的 HTML 格式文档,非标准 .docx,但可在 Word 中正常打开。
根据你的需求选择合适的方法: 普通用户建议使用复制粘贴或在线工具; 开发者可考虑程序化生成。 若需高保真排版,建议先导出为 PDF 再转 Word。