private void publishDoc(string notebook, string section, string id, int position) { Microsoft.Office.Interop.OneNote.Application oneNoteInner; oneNoteInner = new Microsoft.Office.Interop.OneNote.Application(); Console.WriteLine(notebook + " " + section + " " + id); string path = section + ".docx"; if (Directory.Exists(location)) { Directory.CreateDirectory(location); } if (File.Exists(location + path)) { File.Delete(location + path); } try { oneNoteInner.Publish(id, location + path, PublishFormat.pfWord, ""); dgv.Rows[position].Cells[2].Value = DateTime.Now; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/* * Publishes this section as a Word document / .DOCX */ public void publishToDOCX() { //folderName = "\\" + exportFolderBox.Text + "\\"; Microsoft.Office.Interop.OneNote.Application oneNoteInner; oneNoteInner = new Microsoft.Office.Interop.OneNote.Application(); string path = this.fileName + ".docx"; if (Directory.Exists(SettingsManager.location)) { Directory.CreateDirectory(SettingsManager.location); } if (File.Exists(SettingsManager.location + path)) { File.Delete(SettingsManager.location + path); } try { Console.WriteLine(SettingsManager.location + path); oneNoteInner.Publish(this.ID, SettingsManager.location + path, PublishFormat.pfWord, ""); this.exportTime = DateTime.Now.ToString(); } catch (Exception ex) { this.exportTime = "Failed with exception code: " + ex.HResult; MessageBox.Show(ex.Message + " \n while trying to create file: " + SettingsManager.location + path); } }
private void PublishPages(string directory) { Microsoft.Office.Interop.OneNote.Application app = new Microsoft.Office.Interop.OneNote.Application(); string xml; app.GetHierarchy("", HierarchyScope.hsNotebooks, out xml); XDocument doc = XDocument.Parse(xml); foreach (XElement e in doc.Root.Elements()) { string name = (string)e.Attribute("name"); if (name == "Money Specs") { // this is the one! string id = (string)e.Attribute("ID"); app.GetHierarchy(id, HierarchyScope.hsPages, out xml); doc = XDocument.Parse(xml); foreach (XElement section in doc.Root.Elements()) { string sectionName = (string)section.Attribute("name"); string sectionId = (string)section.Attribute("ID"); if (section.Name.LocalName == "Section" && sectionName == "Documentation") { pageIdMap = new Dictionary <string, PageInfo>(); foreach (XElement page in section.Elements()) { string pageName = (string)page.Attribute("name"); Console.Write("Publishing " + pageName + "..."); string pageId = (string)page.Attribute("ID"); string fileName = directory + "\\" + pageName + ".mht"; PageInfo info = new PageInfo() { Name = pageName, Id = pageId, FileName = fileName }; pageIdMap[pageName] = info; if (File.Exists(fileName)) { File.Delete(fileName); } app.Publish(pageId, fileName, PublishFormat.pfMHTML, ""); Console.WriteLine("done"); } } } } } }
private void oneToMht() { Microsoft.Office.Interop.OneNote.Application onenoteApp = new Microsoft.Office.Interop.OneNote.Application(); string sectionId; onenoteApp.OpenHierarchy(srcPath, null, out sectionId); try { //타이틀(제목) 확인을 위한 xml 생성. string xml; XmlDocument document = new XmlDocument(); onenoteApp.GetHierarchy(sectionId, HierarchyScope.hsPages, out xml); document.LoadXml(xml); XmlNodeList xnList = document.GetElementsByTagName("one:Page"); //접근할 노드 string pageId = ""; foreach (XmlNode xn in xnList) { title = xn.Attributes["name"].Value; // get page title pageId = xn.Attributes["ID"].Value; //get page id } document.RemoveAll(); onenoteApp.GetPageContent(pageId, out xml, PageInfo.piAll); document.LoadXml(xml); /*xnList = document.GetElementsByTagName("one:OEChildren/one:T"); //접근할 노드 * * contents = xnList[0].InnerText; * * foreach (XmlNode xn in xnList) * { * title = xn.Attributes["name"].Value; // get page title * pageId = xn.Attributes["ID"].Value; //get page id * * }*/ //document.Save(@"c:\1111.xml"); onenoteApp.Publish(sectionId, dstPath, Microsoft.Office.Interop.OneNote.PublishFormat.pfMHTML, ""); } catch { return; } }