我正在尝试将 Microsoft OneNote 文档转换为 PDF 文件:
Microsoft.Office.Interop.OneNote.Application oneNote;
oneNote = new Microsoft.Office.Interop.OneNote.Application();
string noteBookXML;
oneNote.GetHierarchy(null, HierarchyScope.hsNotebooks, out noteBookXML);
XDocument doc = XDocument.Parse(noteBookXML);
XNamespace ns = doc.Root.Name.Namespace;
foreach (var noteBookNode in from node in doc.Descendants(ns + "Notebook") select node)
{
string id = noteBookNode.Attribute("ID").Value;
string path = "C:\\convert.pdf";
if (File.Exists(path))
File.Delete(path);
try
{
oneNote.Publish(id, path, PublishFormat.pfPDF, "");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
使用上面的代码,我目前正在进行发布调用,跨过它会导致 Microsoft OneNote 停止工作(通用窗口“X 已停止工作,请稍候”),然后出现以下异常:
{System.Runtime.InteropServices.COMException (0x800706BE): The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
at Microsoft.Office.Interop.OneNote.ApplicationClass.Publish(String bstrHierarchyID, String bstrTargetFilePath, PublishFormat pfPublishFormat, String bstrCLSIDofExporter)
at Conversion.OneNoteConverter.run() in G:\Code\OneNoteConversion\Conversion\OneNoteConverter.cs:line 34}
有没有人能够得到这个工作?我在做一些明显错误的事情吗?
提前致谢。
我一直在尝试关注的资源:
http://msdn.microsoft.com/en-us/library/ms788684.aspx
http://social.technet.microsoft.com/Forums/en/office2010/thread/900dd92b-6e5c-40e5-86ec-f18c1a1fc050
http://www.technologyquestions.com/community/threads/api-onenote-2007-publish.117776/