簡體   English   中英

如何創建OneNote 2010部分

[英]How to create OneNote 2010 section

如何使用c#在OneNote 2010筆記本中創建新部分? 根據API ,沒有方法可以這樣做。 但是有一個CreateNewPage方法,所以我想知道是否有類似的部分? 如果沒有,除了操作XML文件之外如何實現這一點(這是我想避免的任務,因為我沒有經驗)?

以下是我添加的代碼段:

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;
        }

基本上我在這里做的是獲取當前查看Section Group或Notebook的路徑,然后將新的section name添加到該路徑,然后調用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);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM