将文件插入/嵌入到 DOCX 文件 - 确定文件类型

发布于 2024-09-12 07:34:35 字数 401 浏览 0 评论 0原文

假设我有一个 API,它允许客户端将文件插入到 DOCX 模板中,它们只需传递文件的路径即可。如果它是一个图像,我只想将图像添加到文件中,如果它是生活 RTF/DOC,那么我可以嵌入它,以便内容可见,如果它是其他类型,如 MP3 或 PDF,那么它可能只是嵌入一个图标。

我想我可以简单地查看文件扩展名,但即便如此,我认为我可能需要正确的文件类型字符串,我看到类似 mainPart.AddEmbeddedObjectPart("application/vnd.openxmlformats-officedocument.oleObject")< 的代码片段/code> 并想知道如何将文件扩展名映射到类型。有没有一个方便的页面包含这些内容?

而且,我认为我确实需要针对图片/其他类型的不同逻辑?嵌入图片会不会很奇怪?

Let's say I have an API which lets clients insert a file into a DOCX template, they just pass a path to the file. If it's an image I just want to add an image to the file, if it's something life RTF/DOC then I can maybe embed it so the content is visible, if it's some other type like MP3 or PDF then it might simply embed with an icon.

I guess I could simply look at file extension, but even then I think I might need the correct file-type string, I see code snippets like mainPart.AddEmbeddedObjectPart("application/vnd.openxmlformats-officedocument.oleObject") and wonder how I can map file-extension to type. Is there a handy page with such things?

And, I assume I do need different logic for pictures/other types? It would be weird to embed a picture?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文