开发者

Create comment in Excel from Html source

So, it's possible to create an excel file from Html. And I've found that many things are possible, like adding images, formatting, etc with just some css tweaks.

However, what I'm trying to do now is get the little red triangle comment to show up.

I've created a blank excel file with nothing but a comment, but it's generated html is a mess. And I'm sure much of it is superfluous. Has anyone done this, or know how I can get it to work?

It would be nice if it were as simple as <td title="comment">text</td>, but it's not.

EDIT: I have the basics required so that html shows a comment when loaded in excel trimmed down to this... I just need to see if I can trim the vml down to something simpler.

It appears the link to the cell it's connected too is this: 0 0

Now I just need to position it properly, initially

I think this is the bare minimum, and I've added a second comment by modifying the html slightly.

But, if you can help trim this down further to it's bare minimum that would be very helpful

<html xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
<body>
    <table>
        <tr>
            <td>cell 1</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>cell 3</td>
        </tr>
    </table>

    <div style='mso-element:comment-list'>
        <div style='mso-element:comment'>
            <!--[if gte mso 9]>
            <xml>
             <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe">
              <v:stroke joinstyle="miter"/>
              <v:path gradientshapeok="t" o:connecttype="rect"/>
             </v:shapetype>
             <v:shape id="_comment1" type="#_x0000_t202" 
                    style='width:96pt;height:55.5pt;z-index:1;visibility:hidden' 
                    fillcolor="infoBackground [80]" o:insetmode="auto">
              <v:textbox style='mso-direction-alt:auto'/>
              <x:ClientData ObjectType="Note">
               <x:Row>0</x:Row>
               <x:Column>0</x:Column>
              </x:ClientData>
             </v:shape>
             <v:shape id="_comment2" type="#_x0000_t202" 
                    style='width:96pt;height:55.5pt;z-index:1;visibility:hidden' 
                    fillcolor="infoBackground [80]" o:insetmode="auto">
              <v:textbox style='mso-direction-alt:auto'/>
              <x:Client开发者_开发技巧Data ObjectType="Note">
               <x:Row>1</x:Row>
               <x:Column>3</x:Column>
              </x:ClientData>
             </v:shape>
            </xml>
            <![endif]-->
            <div v:shape="_comment1" >
                This is a comment
            </div>
            <div v:shape="_comment2" >
                This is another comment
            </div>
        </div>
    </div>
</body>
</html>


There's no simple way I've been able to determine. But here's a complicated way:

  1. Take your simple html file and open it in Excel.
  2. Add a comment to a cell.
  3. Save it, preserving the html format.

The reason that this isn't simple is that what Excel actually does at that point is to create a folder containing some support files and a new version of the original files - essentially an HTML representation of the Excel file. If you RE-open this file with the support files in place, you'll get your comment.

What this tells you is that there is a prospective html format (though it doesn't exist in a single file) that gives you your comment, and you just need to reverse engineer it.

So is it possible? Yes. Is it worth the trouble? Well, given that Microsoft never wrote anything in a hundred lines of code that they couldn't write in a thousand - almost certainly not.

I'm curious as to what else you've been able to accomplish along these lines, though. I've made this answer a community wiki so you can share it if you're interested.


I think this is the bare minimum, and I've added a second comment by modifying the html slightly.

<html xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
<body>
    <table>
        <tr>
            <td>cell 1</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>cell 3</td>
        </tr>
    </table>

    <div style='mso-element:comment-list'>
        <div style='mso-element:comment'>
            <!--[if gte mso 9]>
            <xml>
             <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe">
              <v:stroke joinstyle="miter"/>
              <v:path gradientshapeok="t" o:connecttype="rect"/>
             </v:shapetype>
             <v:shape id="_comment1" type="#_x0000_t202" 
                    style='width:96pt;height:55.5pt;z-index:1;visibility:hidden' 
                    fillcolor="infoBackground [80]" o:insetmode="auto">
              <v:textbox style='mso-direction-alt:auto'/>
              <x:ClientData ObjectType="Note">
               <x:Row>0</x:Row>
               <x:Column>0</x:Column>
              </x:ClientData>
             </v:shape>
             <v:shape id="_comment2" type="#_x0000_t202" 
                    style='width:96pt;height:55.5pt;z-index:1;visibility:hidden' 
                    fillcolor="infoBackground [80]" o:insetmode="auto">
              <v:textbox style='mso-direction-alt:auto'/>
              <x:ClientData ObjectType="Note">
               <x:Row>1</x:Row>
               <x:Column>3</x:Column>
              </x:ClientData>
             </v:shape>
            </xml>
            <![endif]-->
            <div v:shape="_comment1" >
                This is a comment
            </div>
            <div v:shape="_comment2" >
                This is another comment
            </div>
        </div>
    </div>
</body>
</html>


This was so timely and quite appreciated! I just implemented now and it seems to work fine. The largest issue is having to predetermine the row and col which "flex" for me. I'm looking to see if an anchor can be used instead of row and column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜