C# 以编程方式在excel中插入单元格注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/222760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert cell comments in excel programmatically
提问by Adones Cunha
What's the better way to insert cell comments in excel 2007 files programmatically using c# and .net 3.5?
使用 c# 和 .net 3.5 以编程方式在 excel 2007 文件中插入单元格注释的更好方法是什么?
采纳答案by kenny
I just did exactly that but with MS Word (using Microsoft.Office.Interop.Word
我就是这样做的,但是使用 MS Word(使用 Microsoft.Office.Interop.Word
range.Comments.Add ( range, ref _categoryMessage );
range.Comments.Add ( range, ref _categoryMessage );
So, I would suggest using Microsoft.Office.Interop.Excel and the similar method. Consider this from MSDN:
所以,我建议使用 Microsoft.Office.Interop.Excel 和类似的方法。从 MSDN 考虑这一点:
http://msdn.microsoft.com/es-es/library/microsoft.office.interop.excel.range.addcomment.aspx
http://msdn.microsoft.com/es-es/library/microsoft.office.interop.excel.range.addcomment.aspx
Also see thistoo
也看到这个太
回答by Alexandre Brisebois
Have you tried using VSTO ? You can easily load an Excel document and manipulate it. To add a comment to a cell, load the file, activate the worksheet, then select the cell as a range and set the comment.
你试过使用 VSTO 吗?您可以轻松加载 Excel 文档并对其进行操作。要向单元格添加注释,请加载文件,激活工作表,然后选择单元格作为范围并设置注释。
回答by Daniil Shevelev
The accepted answer points in the right direction, but the correct syntax is:
接受的答案指向正确的方向,但正确的语法是:
Excel.Range cell;
cell.AddComment("My comment");
回答by Cihan
Excel._Worksheet oSheet =
(Microsoft.Office.Interop.Excel._Worksheet) excelWorkbook.ActiveSheet;
oSheet.Cells[2, 3].Cells.AddComment("Selam");