如何使用 Open XML SDK 2.0 将注释添加到 Excel 2007 中的单元格?
有没有人曾经有幸弄清楚如何使用 Open XML SDK 2.0 向 Excel 添加注释?我找不到任何关于从哪里开始解决这个问题的文档。
Has anyone ever had any luck figuring out how to add a comment to Excel using the Open XML SDK 2.0? I couldn't find any documentation on where to get started on this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的代码将获取您要添加注释的工作表,然后迭代 commentsToAdd 字典。字典键是单元格引用(即A1),值是要添加的注释文本。
将为形状创建 VML XML 的帮助程序方法:
帮助程序找出注释的列索引和坐标 形状:
完成后不要忘记保存工作表和工作簿,以便查看更改。
The below code will take the worksheet that you want to add comments to and then iterate over the commentsToAdd dictionary. The dictionary key is the cell reference (ie. A1) and the value is the comment text to be added.
Helper method that will create the VML XML for the Shape:
Helpers to figure out the Column Index and coordinates for the comment Shape:
Don't forget to save your worksheet and workbook once you are done in order to see the changes.
许多人会问使用 OpenXML“如何做这个”/“如何做那个”。
最常见的答案是 OpenXML 使用起来很痛苦(我同意),请参阅第 3 方库(特别是 ClosedXML< /a>)。
如果您不使用第 3 方库,那么我想回答基于此线程的一般提示:http://social.msdn.microsoft.com/Forums/office/en- US/81f767d0-15ac-42fe-b122-6c5c02b6c373/cell-color-and-add-comment?forum=oxmlsdk
有一个选项反映代码,可以为您提供有关正在发生的情况的大量提示,请参阅下面的(不完整)示例:
由于它是自动生成的代码,因此可以简化/内联/减少。一两周后,你就会加快速度。
Many people ask "how to do this" / "how to do that" using OpenXML.
The most frequent answer say that OpenXML is painful to work with (I agree) refer to 3-rd party library (specifically ClosedXML).
If you are not using a 3-rd party library then I would like to answer with a general tip based on this thread: http://social.msdn.microsoft.com/Forums/office/en-US/81f767d0-15ac-42fe-b122-6c5c02b6c373/cell-color-and-add-comment?forum=oxmlsdk
There is an option reflect code that gives you a lot of hints about what is going on, see (incomplete) example below:
As it is autogenerated code it can be simplified / inlined / reduced. After a week or two you'll get into speed.