使用 AJAX 加载 MS Word 文件

发布于 2024-08-14 09:36:57 字数 93 浏览 2 评论 0原文

我想将一些 Microsoft Word 文件中的文本动态加载 (AJAX) 到网页中。因此,我可能有一个指向我写的文章的链接,当鼠标悬停时,它会加载工具提示中的前几句话。

I want to dynamically load (AJAX) the text from some Microsoft Word files into a webpage. So I might have a link to essays I've written and upon mouseover have it load the first few sentences in a tooltip.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北笙凉宸 2024-08-21 09:36:57

仅当您有解析器时。我认为新格式是带有 XML 模式的 zip 存档。但旧的只是二进制的。

那里有一些解析器。

我知道 wvWare 但它似乎已经过时了。 (http://wvware.sourceforge.net/

这也许值得一看:http://poi.apache.org/hwpf/index.html

是的,忘了提及如何做到这一点。 :-)
首先,您需要让 javascript 通过 ajax 请求数据。服务器端必须负责解析并将文本返回给 javascript。这将是一件令人头疼的事情。我自己没有这样做过,也从未尝试过我链接的解析器,所以我不确定它们是否适合您。图像、样式表等……不确定是否有用。

至少,祝你好运。

Only if you have a parser. I think the new format is a zip archive with XML schema. But the old one is just binary.

There are some parsers out there.

I know of wvWare but it seems it's outdated. (http://wvware.sourceforge.net/)

This is maybe something worth looking at: http://poi.apache.org/hwpf/index.html

And yeah, forgot to mention how to do this. :-)
First you need to make the javascript ask for the data through ajax. The serverside has to take care of the parsing and return the text to the javascript. This will be a pain in the ass. I haven't done this myself and have never tried the parsers I linked, so I'm not sure if they suit you. Images, stylesheets, etc.... not sure if that will be useable.

At least, good luck.

我们只是彼此的过ke 2024-08-21 09:36:57

出于安全原因,无法仅使用 Javascript 将本地文件(例如 Word 文档)直接加载到页面中。用户需要将文件上传到服务器,您需要在服务器上解析该文件,然后您可以使用 Ajax 将您喜欢的任何结果加载到页面中。

For security reasons, it is not possible to directly load a local file (such as a Word document) into the page using simply Javascript. The user will need to upload the file to the server, which you will want to parse on the server and then you can load whatever result you like into the page using Ajax.

疯狂的代价 2024-08-21 09:36:57

听起来您的意思是要将文件(例如论文)上传到服务器以允许用户下载它们,并且想要创建一个服务器端页面来解析文件并打印前几行(因此可以通过悬停时显示预览的 AJAX 方法)。

为了推荐一个用于此目的的工具,我们需要知道这些是“旧”Word 格式(Office 2003 - 扩展名是 .doc)还是“新”Word 格式(Office 2007 - 扩展名是 .docx)。

了解您使用什么来创建服务器端页面也很有好处,因为不同的文档阅读工具支持不同的编程语言。如果您使用 Java 来读取 .doc 文件,您可以使用我们在我工作地点使用的工具,即 POI (

如果所有这些对您来说都是希腊语,并且您之前没有开发自定义服务器端 Web 代码的经验,那么这可能会带来不必要的痛苦,您应该考虑替代方案(例如手动创建 3 行文本“预览”页面)对于每个常规页面,然后仅显示该内容)。

It sounds like you mean to upload your files (e.g. essays) to your server to allow users to download them, and want to create a server-side page that will parse the files and print the first few lines (so it can be called by an AJAX method that displays a preview on hover).

To suggest a tool for this, we'll need to know whether these are "old" Word format (Office 2003 - extension is .doc) or "new" Word format (Office 2007 - extension is .docx).

It will also be good to know what you're using to create your pages server-side, since different document-reading tools support different programming languages. If you're using Java to read .doc files, you can use the tool we use at my place of work, which is POI (http://poi.apache.org/). If you're using something else, try searching google for {read in }, e.g. {read .docx in ruby}.

If all of this is Greek to you and you have no prior experience with developing custom server-side web code, this is probably going to be unnecessarily painful and you should consider an alternative (like manually creating a 3-line text "preview" page for each regular page, and then just showing that).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文