如何使用 c# 在 OneNote 2010 笔记本中创建新分区?根据API,没有方法可以这样做。但是有一个 CreateNewPage 方法,所以我想知道部分是否有类似的东西?如果没有,除了操作 XML 文件(这是一项我想避免的任务,因为我没有这方面的经验)之外,如何实现这一点?
问问题
2833 次
1 回答
3
这是我添加的代码片段:
public bool AddNewSection(string SectionTitle, out string newSectionId)
{
try
{
string CurrParentId;
string CurrParentName;
string strPath;
CurrParentId = FindCurrentlyViewedSectionGroup(out CurrParentName);
if (string.IsNullOrWhiteSpace(CurrParentId) || string.IsNullOrWhiteSpace(CurrParentName))
{
CurrParentId = FindCurrentlyViewedNotebook(out CurrParentName);
if (string.IsNullOrWhiteSpace(CurrParentId) || string.IsNullOrWhiteSpace(CurrParentName))
{
newSectionId = string.Empty;
return false;
}
strPath = FindCurrentlyViewedItemPath("Notebook");
}
else
strPath = FindCurrentlyViewedItemPath("SectionGroup");
if (string.IsNullOrWhiteSpace(strPath))
{
newSectionId = string.Empty;
return false;
}
SectionTitle = SectionTitle.Replace(':', '\\');
SectionTitle = SectionTitle.Trim('\\');
strPath += "\\" + SectionTitle + ".one";
onApp.OpenHierarchy(strPath, null, out newSectionId, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
onApp.NavigateTo(newSectionId, "", false);
}
catch
{
newSectionId = string.Empty;
return false;
}
return true;
}
基本上我在这里所做的是获取当前查看部分组或笔记本的路径,然后将新部分名称添加到该路径,然后调用 OpenHierarchy 方法。OpenHierarchy 创建一个提供标题的新部分并返回它的 id。
以下是我创建一个新部分并导航到它的地方:
onApp.OpenHierarchy(strPath, null, out newSectionId, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
onApp.NavigateTo(newSectionId, "", false);
所以可以这样写:
static void CreateNewSectionMeetingsInWorkNotebook()
{
String strID;
OneNote.Application onApplication = new OneNote.Application();
onApplication.OpenHierarchy("C:\\Documents and Settings\\user\\My Documents\\OneNote Notebooks\\Work\\Meetings.one",
System.String.Empty, out strID, OneNote.CreateFileType.cftSection);
}
于 2012-11-14T06:10:32.987 回答