PHP 生成的 Word 文档的页边距(使用 fopen)
我最近发布了一个关于如何在不使用 COM 对象的情况下生成 .doc 文件的问题 - 我得到了一些很好的答复(谢谢!),但不幸的是我需要该文档与旧的 .doc 格式而不是 .docx 兼容,因为我们这里都使用Office 2003,没有兼容插件。
我有以下代码,它生成一个非常基本的文档,但可能会完成这项工作,问题是标题图像非常大(而且必不可少),除非我降低页边距,否则无法容纳...我尝试将 HTML/Body 的边距和填充更改为 0 但不幸的是没有运气:
$fp = fopen("test.doc", 'w+');
$str = "<html><body><img src=\"http://url/header_image.png\">
<B>Content</B></body></html>";
fwrite($fp, $str);
fclose($fp);
I recently posted a question on how to generate a .doc file without using the COM object - I had some great replies (thank you!) but unfortunately I need the document to be compatible with the old .doc format and not .docx since we're all using Office 2003 here, without the compatibility plugin.
I have the following code which generates a very basic document, but one that will probably do the job, the problem is the header image is very large (and essential) and won't fit in unless I lower the page margin... I tried changing the margin and padding of HTML/Body to 0 but had no luck unfortunately:
$fp = fopen("test.doc", 'w+');
$str = "<html><body><img src=\"http://url/header_image.png\">
<B>Content</B></body></html>";
fwrite($fp, $str);
fclose($fp);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您实际上并没有创建 Word 文件,而只是 Word 使用其自己的内部渲染器格式化的 HTML 文件。
您也可以将它们作为
html
文件分发。我能想到的唯一好处是您只需针对 Word 版本而不是所有浏览器。
You are not actually creating a Word file, just a HTML file that Word is formatting using its own internal renderer.
You may as well just distribute them as
html
files.The only benefit I can think of is that you only have to target versions of Word rather than all browsers.
晚了几年,但可能对其他人有帮助:
http://sunsetsoftware.blogspot.com /2012/01/how-to-create-word-document-with-html.html
这是有趣的部分。使其纵向:
A couple years late, but it might help someone else:
http://sunsetsoftware.blogspot.com/2012/01/how-to-create-word-document-with-html.html
That is the interesting section. To make it portrait: