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 に答える