将 Outlook 电子邮件的所有附件转换为 PDF
我正在为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的办法是使用注册表来找出与扩展关联的应用程序。如果您查看此链接:
关联扩展的脚本到程序
它显示您需要在注册表中查找的位置。
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.