OneNote,使用 UpdatePageContent 插入元素 [英] OneNote, inserting elements with UpdatePageContent

查看:36
本文介绍了OneNote,使用 UpdatePageContent 插入元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试查找是否可以通过 Microsoft.Office.Interop.OneNote 参考中的 UpdatePageContent 将内容添加到 oneNote 页面.

I tried to find if it was possible to add content to a oneNote page via UpdatePageContent in the Microsoft.Office.Interop.OneNote reference.

我想用我在 XML 中制作的默认模板创建一个页面,但是 msdn 的文档告诉我这个功能只允许结构:

I want to create a page with a default template that I made in XML, but the documation of msdn said me that this function only allow the structure :

msdn 文档:

必须包含在传递给 UpdatePageContent 方法的 XML 代码中的唯一对象是已更改的页面级对象(例如轮廓、页面上的图像或页面上的墨迹).此方法不会修改或删除您未在 bstrPageChangesXmlIn 参数中指定的页面级对象.该方法完全替换了页面级对象,例如轮廓,其 ID 与您传递的对象的 ID 匹配.因此,您必须在代码中完全指定所有页面级对象,包括它们的现有内容和您要对它们进行的更改.

The only objects that you must include in the XML code that you pass to the UpdatePageContent method are page-level objects (such as outlines, images on the page, or ink on the page) that have changed. This method does not modify or remove page-level objects that you do not specify in the bstrPageChangesXmlIn parameter. The method entirely replaces page-level objects, such as outlines, whose IDs match those of the objects you pass. Consequently, you must fully specify all page-level objects in your code, including their existing content and changes you want to make to them.

我的问题是:我可以使用这个库在页面中添加元素吗?如果是这样,如何?

my question is : can I, with this library, add element in a page? if so, how?

谢谢

推荐答案

您可以使用 OMSpy 工具,用于调查页面内容结构.以下是一些可帮助您入门的示例:

You can use OMSpy tool to investigate Page content structure. Following are some samples to help you get started:

当你有pageId时设置页面标题

To Set page title when you have pageId

        private static void SePageTitle(string pageId, string pageTitle)
    {
        Microsoft.Office.Interop.OneNote.Application m_app = new Microsoft.Office.Interop.OneNote.Application();
        string strPagTitle = "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2010/onenote\" ID=\"{0}\" >" +
              "<one:Title selected=\"partial\" lang=\"en-US\">" +
                "<one:OE style=\"font-family:Calibri;font-size:17.0pt\">" +
                  "<one:T><![CDATA[{1}]]></one:T> " +
                "</one:OE>" +
              "</one:Title>" +
            "</one:Page>";
        strPagTitle = string.Format(strPagTitle, pageId, pageTitle);
        m_app.UpdatePageContent(strPagTitle);
    }

当您有 pageId 时将元素添加到页面:

Add element to page when you have pageId:

        private static void SetElementInPage(string pageId)
    {
        Microsoft.Office.Interop.OneNote.Application m_app = new Microsoft.Office.Interop.OneNote.Application();
        string strPageContent = "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2010/onenote\" ID=\"{0}\" >" +
            "<one:Outline>" +
                "<one:Position x=\"36.0\" y=\"86.4000015258789\" z=\"0\" />" + 
                "<one:Size width=\"117.001953125\" height=\"40.28314971923828\" />" + 
                "<one:OEChildren>" + 
                    "<one:OE>" +
                        "<one:T><![CDATA[This is a sample data added to test out OneNote API functionality.  Following is a list item.]]></one:T>" + 
                    "</one:OE>" +
                "</one:OEChildren>" +
                "<one:OEChildren indent=\"2\">" +
                    "<one:OE  alignment=\"left\">" +
                        "<one:List>" +
                            "<one:Bullet bullet=\"2\" fontSize=\"11.0\" />" +
                        "</one:List>" + 
                        "<one:T><![CDATA[A for Apple]]></one:T>" +
                    "</one:OE>" +
                    "<one:OE  alignment=\"left\">" +
                        "<one:List>" +
                            "<one:Bullet bullet=\"2\" fontSize=\"11.0\" />" +
                        "</one:List>" + 
                        "<one:T><![CDATA[B for Ball]]></one:T>" +
                    "</one:OE>" +
                    "<one:OE  alignment=\"left\">" +
                        "<one:List>" +
                            "<one:Bullet bullet=\"2\" fontSize=\"11.0\" />" +
                        "</one:List>" + 
                        "<one:T><![CDATA[C for Cat]]></one:T>" +
                    "</one:OE>" +
               "</one:OEChildren>" +
            "</one:Outline>" +
            "</one:Page>";
        strPageContent = string.Format(strPageContent, pageId);
        m_app.UpdatePageContent(strPageContent);
    }

这篇关于OneNote,使用 UpdatePageContent 插入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆