如何在 HTML/PHP 中显示格式化的 Word 文档?
在 HTML/PHP 中显示格式化的 Word 文档的最佳方式是什么?
这是我目前拥有的代码,但它没有格式化它:
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("ACME.doc"));
// Extract content.
$content = (string) $word->ActiveDocument->Content;
echo $content;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
What is the best way to display a formatted Word Doc in HTML/PHP?
Here is the code I currently have but it doesn't format it:
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("ACME.doc"));
// Extract content.
$content = (string) $word->ActiveDocument->Content;
echo $content;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我明白了这一点。查看读取 Word 文档并将其格式化为 HTML 的解决方案:
有几件事...在我的 PHP 页面顶部添加了“charset=UTF-8”,添加了一堆带有问号的菱形...我删除了那个并且它工作得很好。
另外,另存为必须具有完整路径,至少在本地,我添加了它才能使其正常工作。
再次感谢您的帮助。
I figured this out. Check out the solution to reading a Word Doc and formatting it in HTML:
Couple of things... Having "charset=UTF-8" at the top of my PHP page was adding a bunch of diamonds with questions marks... I deleted that and it works perfectly.
Also, the SaveAs has to have the full path, at least locally, I added that to get it to work.
Thanks again for your help.
我对 COM 一无所知,但是浏览 MSDN 上的 Word API 文档,看起来您最好的选择是使用
Document.SaveAs
另存为wsFormatFilteredHTML
到临时文件,然后将该 HTML 提供给用户。请务必选择过滤 HTML,否则您将得到有史以来最糟糕的标签汤。I know nothing about COM, but poking around the Word API docs on MSDN, it looks like your best bet is going to be using
Document.SaveAs
to save aswsFormatFilteredHTML
to a temporary file, then serving that HTML to the user. Be sure to pick the filtered HTML, otherwise you're going to get the soupiest tag soup ever.我需要正确的 XHTML,但 Office 不会提供该信息(我不理解这一点)。如果需要,您可以使用 JTidy 或 TagSoup 等工具来修复 HTML。比照。 http://slideguitarist.blogspot.com/2011/03 /导出-word-documents-to-html.html
I needed correct XHTML, which Office won't give you (I do not understand that). You can use tools such as JTidy or TagSoup to fix the HTML, if you need to. Cf. http://slideguitarist.blogspot.com/2011/03/exporting-word-documents-to-html.html