在剪贴板中添加 google 个电子表格注释

Add google spreadsheet notes in clipboard

我目前正在 javascript 中创建 html table 并将其放入剪贴板以粘贴到 google sheet。但是,我还需要一些单元格来评论,我无法添加评论。

我正在使用 this 剪贴板查看器来了解 google sheet 是如何做到这一点的,但我还是无法让它工作。

我在 google 传播sheet 中输入了一些数据并复制了一行空单元格,一个单元格有一个值,一个单元格有一个值和一个注释。这是我从 google sheet:

复制到剪贴板(html 版本)时的(格式化版本)
<html>
    <body>
        <!--StartFragment-->
        <meta name="generator" content="Sheets"/>
        <style type="text/css">
            <!--
                td {border: 1px solid #ccc;}
                br {mso-data-placement:same-cell;}
            -->
        </style>

        <table 
            xmlns="http://www.w3.org/1999/xhtml" 
            cellspacing="0" 
            cellpadding="0" 
            dir="ltr" 
            border="1" 
            style="
                table-layout:fixed;
                font-size:10pt;
                font-family:
                arial,sans,sans-serif;
                width:0px;
                border-collapse:collapse;
                border:none" >

            <colgroup>
                <col width="100"/>
                <col width="100"/>
                <col width="100"/>
            </colgroup>

            <tbody>
                <tr style="height:21px;">
                    <td 
                        style="
                            overflow:hidden;
                            padding:2px 3px 2px 3px;
                            vertical-align:bottom;" >
                    </td>
                    <td 
                        style="
                            overflow:hidden;
                            padding:2px 3px 2px 3px;
                            vertical-align:bottom;
                            text-align:right;" 
                        data-sheets-value="{&quot;1&quot;:3,&quot;3&quot;:0}" >
                            0
                    </td>
                    <td 
                        style="
                            overflow:hidden;
                            padding:2px 3px 2px 3px;
                            vertical-align:bottom;" 
                        data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;?&quot;}" 
                        data-sheets-note="test note">
                            ?
                    </td>
                </tr>
            </tbody>
        </table>
        <!--EndFragment-->
    </body>
</html>

如果我粘贴到另一个地方,注释也会被粘贴,所以这在某种程度上起作用了。

似乎关键应该是data-sheets-note属性,但它不是那样工作的。例如,我将以下内容推送到剪贴板(HTML 格式):

<html>
    <body>
        <!--StartFragment-->
        <table>
            <tr>
                <td>1</td>
                <td data-sheets-note="test2">2</td>
            </tr>
        </table>
        <!--EndFragment-->
    </body>
</html>

它会粘贴到展开sheet,但注释不会添加到单元格中。

如果我采用前面的示例并将其再次推送到剪贴板(HTML 格式),我可以再次粘贴到 google sheet 中,并且注释也会被添加, 所以格式是正确的,存储笔记的属性也是正确的(因为它是唯一保存笔记内容的地方,它被粘贴了)。

那我错过了什么?

data-sheets-note 属性确实是正确的。但是,为了让它被接受,我们需要撒谎。必须要说明的是剪贴板的内容是googlesheet自己生成的

我们可以使用元标记来判断:

<html>
    <body>
        <!--StartFragment-->
        <meta name="generator" content="Sheets"/>
        <table>
            <tr>
                <td>1</td>
                <td data-sheets-note="test2">2</td>
            </tr>
        </table>
        <!--EndFragment-->
    </body>
</html>

现在 sheet 也能识别评论了。