通过Graph API使用OneNote页面内容 [英] Working with OneNote Page Content via the Graph API

查看:82
本文介绍了通过Graph API使用OneNote页面内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过图形API使用OneNote时遇到很多问题.

I have a number of issues when working with OneNote via the graph api.

我知道OneNote所使用的不是纯HTML,他们需要将其前后转换为API……但这似乎并不复杂.

I understand that what OneNote uses is not straight html and they need to convert it back and forward for the API... but this would not appear to be that complex a task.

我正在处理内容中的标签,并且需要能够更新标签元素.没关系,除了我有缩进的项目(p或li)标签列表的地方.

I am processing tags in the content and need to be able to update the tag element. It is fine except for where I have a list of items (p or li) tags where there are indents.

已更新

如果我的笔记中有这样的项目

If there are items like this in my onenote

没有嵌入图像的权利...所以这里是链接 https://xomq6w.ch.files.1drv.com/y4mc-mJZRhkI5c_fvOAbHGOnzEKVNKgxTHLop-OHfNofncLcC2gUc_Z_aYi0sgrc3hxIxxWpnvwRFc7p-reL5mX8J5pp1ePaY0V2McibdocMTplud7lxcso0EwAGJpHpBkcyLbcsLxDUpoYZ9T5XgCCxxmfUwQhHFPFQdFscfQoDPp7ZA-vCNbErgqyz0FK7prVaeMjs8LpiftMKu6-Xcv7Rg?width=160&height=541&cropmode=none

Dont have the rights to embed an image... so here is the link https://xomq6w.ch.files.1drv.com/y4mc-mJZRhkI5c_fvOAbHGOnzEKVNKgxTHLop-OHfNofncLcC2gUc_Z_aYi0sgrc3hxIxxWpnvwRFc7p-reL5mX8J5pp1ePaY0V2McibdocMTplud7lxcso0EwAGJpHpBkcyLbcsLxDUpoYZ9T5XgCCxxmfUwQhHFPFQdFscfQoDPp7ZA-vCNbErgqyz0FK7prVaeMjs8LpiftMKu6-Xcv7Rg?width=160&height=541&cropmode=none

我点击了图形api,以通过图形api浏览器获取具有以下网址的内容

I hit the graph api to get the content with the following url via the graph api explorer

GET-返回的html看起来像这样(请注意,缩进不存在)

the html that comes back will look like this (note that the indents are not there)

<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
    <div id="div:{f115c5ea-0481-0f03-31aa-07b94321c323}{65}" style="position:absolute;left:264px;top:139px;width:624px">
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{67}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 1</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{71}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2a</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{73}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2b</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{76}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 3</p>
    </div>
</body>

如果我修补具有此类子项的项,以设置ID(将ID保留在其中……将其转换为永久性的数据ID),以便以后进行更新,甚至关闭标签:

And if I patch the ones that have child items like this to set ids (leaving the id in there... turns it into a permanent data-id) for later updates or even to close a tag:

PATCH - https://graph.microsoft.com/beta/users/myname/onenote/pages/0-c9861926a1e8080518ca3750afa63800!1-2B303C571455A20B!102505/content?includeIDs=true

[
  {
    'target':'p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}',
    'action':'replace',
    'content':'<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>'
  }
]

更新将被处理,然后内容将被更新为此:

The update will be processed and then the content will be updated to this:

图像位置: https://开头kw9psa.ch.files.1drv.com/y4mplcvzocTmhN9DZBpFt4Sic3AOpxe2Ik4r7VX_0Joxs5ay9woTUYZufKSr0ojcfwQckovsJv5__fSrDx1GqWK9cFa2yQ7uFPE8JQOBwPyYn6PQZHDMM4N9JB4IXF4Rs7dIDoqa0XYfjz93qGiI97Ais99l04QxWZyV1Og5eXRguUYlBoNTwXIuzFEbKZfA03mt_ynxXCjbM7CFHYP99_QgQ?width=160&height=134&cropmode=none

<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
    <div id="div:{f115c5ea-0481-0f03-31aa-07b94321c323}{65}" style="position:absolute;left:264px;top:139px;width:624px">
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{67}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 1</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{71}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2a</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{73}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2b</p>
        <p id="p:{78cb2ca5-efec-4e6f-a763-12e9cac6a2b5}{2}" lang="en-US" data-tag="to-do" data-id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>
        <p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{76}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 3</p>
    </div>
</body>

对于嵌套的ul/ol项目本质上也是如此……我也尝试替换整个列表而不是单个项目,但是api调用错误而没有其他信息.嵌套的项目符号列表似乎也丢失了父项目符号.

The same essentially happens for nested ul/ol items... I also tried replacing the whole list instead of individual items, but the api call errors out with no additional information. Nested bulleted lists also seem to lose the parent bullet.

我尝试批处理所有项目的所有更新,一次执行一次,以相反的顺序进行操作.

I have tried batching all updates for all items, doing one at a time, reversing the order.

很有趣,如果我执行插入操作,则保留文本缩进和顺序,但是没有删除/删除补丁可以清除旧文本...例如

Funnily enough if I do an insert then the text indents and order are retained, but there is no delete/remove patch to clean out the old text... e.g.

[
  {
    'target':'p:{56d579c0-1203-0224-0587-6fe03fb82539}{34}',
    'action':'insert',
    'position':'before',
    'content':'<p data-id="My_own_id" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 1</p>'
  },
  {
    'target':'p:{56d579c0-1203-0224-0587-6fe03fb82539}{34}',
    'action':'<tried replace or delete/remove hoping it was undocumented>',
    'content':'<tried blank or just a span>'
  }
]

其他问题包括

  • 表格失去了显示网格线的属性
  • 如果我更新页面上的任何文本,则没有文本的标签不会返回甚至消失

部分答案

这里是非项目符号列表问题的部分答案...感谢codeye向我指出了正确的方向.

Here is a partial answer for the non bulletted list issue... thanks to codeye for pointing me in the right direction.

通过在现有元素之前插入我的元素,它可以保留顺序.

By inserting my element before the existing one it retains the order.

[
  {
    'target':'p:{20781e6d-ba99-4fca-9994-622720cad7f8}{249}',
    'action':'insert',
    'position':'before',
    'content':'<p data-id="test" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>'
  }
]

然后使用以下命令删除旧的,以保留格式.而且由于它是一个空的div,因此OneNote不会添加该元素.

Then removing the old one with the following it looks to retain the formatting. And as it is an empty div OneNote doesn't add the element.

[
  {
    'target':'p:{20781e6d-ba99-4fca-9994-622720cad7f8}{249}',
    'action':'replace',
    'content':'<div></div>'
  }
]

推荐答案

表格边框的解决方案

使用表时,请使用border属性而不是style.

When work with tables use border attribute instead of style.

API将为您返回带边框的表,该表的边框为<table style="border:1px solid;border-collapse:collapse">...</table>.使用table.style.border查找是否有边框(可以是1px或0px).要为表格设置边框,请使用border属性:<table border="1">...</table>.

API returns you a table with borders as <table style="border:1px solid;border-collapse:collapse">...</table>. Use table.style.border to find if there is a border (it can be 1px or 0px). To set border for the table use border attribute: <table border="1">...</table>.

tdborder属性将被忽略.

这篇关于通过Graph API使用OneNote页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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