将 Outlook 电子邮件的所有附件转换为 PDF

发布于 2024-10-11 11:18:16 字数 1299 浏览 7 评论 0原文

我正在为 Outlook07 编写一个插件,它应该存储电子邮件的文本 以及所有附件都在单独的 pdf 文件中。当然这仅适用于合理的附件,对于 zip 文件等没有意义。

我已经到了所有文件都存储在临时目录中的地步(对于每封邮件)。邮件 本身很容易转换,但我在附件方面遇到了麻烦。

这个想法是使用每个相应的办公室互操作中的exportAs方法,因此我不必在客户端电脑上安装其他软件。

要导出每个文件及其相应的办公应用程序,我首先必须找出哪个办公应用程序可以打开它。当然,首先想到的是尝试扩展,但必须有一些更有效的方法,然后

if(fileExt == "doc" or "docx" or "wordformat i forgot") Open Word and Convert
if(fileExt == "xls") Open Excel and Convert

我尝试在 msdn 文档和 google 中找到一些东西,但 Office.Interops 是 记录真的很糟糕,这使得我很难到达现在的位置。并开幕 上述意义上的文档没有在任何地方被涵盖。

任何暗示都会让我非常高兴。

编辑 - 以下是我如何转换 Word 文档的示例:

Word.Application wordApp = new Word.Application();
object oFilename = filename + ".html";
wordApp.Documents.Open(ref oFilename, x,x,x,x,x,x);
wordApp.ActiveDocument.ExportAsFixedFormat(filename+".pdf",
Word.WdExportFormat.wdExportFormatPDF,x,x,x,x,x);
wordApp.ActiveDocument.Close();
wordApp.Close();
wordApp = null;

编辑 - 成功之路:

var key = registry.ClassesRoot.OpenSubKey(Path.GetExtension(filename));
string openType = key.GetValue("").ToString().ToLower();

if(openType.StartsWith("word.")) return DocumentType.Word;
if(openType.StartsWith("excel.")) return DocumentType.Excel;

return DocumentType.Unusable;

看起来不错。感谢您的帮助,这是周末开始的好方法。

I'm in the process of writing an Add-in for Outlook07 which should store the text of an email
and all it's attachments in separate pdf files. Of course this is only for reasonable attachments, it would not make sense for zip files and such.

I got to the point where all files are stored in a temp dir (for each mail). The mail
itself is easily converted but i'm having trouble with the attachments.

The idea is to use the exportAs method from each corresponding office interop, so i do not have to install aditional software on client pcs.

To export each file with it's corresponding office application I first have to find out which office application can open it. Sure, the first thing that comes to mind is trying out the extensions but there has to be some more efficient way then

if(fileExt == "doc" or "docx" or "wordformat i forgot") Open Word and Convert
if(fileExt == "xls") Open Excel and Convert

I've tried to find something in the msdn documentations and google but Office.Interops are
REALLY badly documented which made it already hard to get where I am now. And opening
documents in the above sense isn't covered anywhere.

Any hint at all would make me really happy.

EDIT - following is the example how i convert word documents:

Word.Application wordApp = new Word.Application();
object oFilename = filename + ".html";
wordApp.Documents.Open(ref oFilename, x,x,x,x,x,x);
wordApp.ActiveDocument.ExportAsFixedFormat(filename+".pdf",
Word.WdExportFormat.wdExportFormatPDF,x,x,x,x,x);
wordApp.ActiveDocument.Close();
wordApp.Close();
wordApp = null;

EDIT - the road to success:

var key = registry.ClassesRoot.OpenSubKey(Path.GetExtension(filename));
string openType = key.GetValue("").ToString().ToLower();

if(openType.StartsWith("word.")) return DocumentType.Word;
if(openType.StartsWith("excel.")) return DocumentType.Excel;

return DocumentType.Unusable;

It's looking good. Thx for the help, great way to start into the weekend.

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

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

发布评论

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

评论(1

眼中杀气 2024-10-18 11:18:16

最好的办法是使用注册表来找出与扩展关联的应用程序。如果您查看此链接:

关联扩展的脚本到程序

它显示您需要在注册表中查找的位置。

The best thing to do would be to use the registry to find out what application is associated with the extension. If you have a look at this link:

Script to associate an extension to a program

It shows where in the registry you need to look.

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