What's the better way to insert cell comments in excel 2007 files programmatically using c# and .net 3.5?
Asked
Active
Viewed 1.9k times
5
-
How are you currently working with the document? – Mitchel Sellers Oct 21 '08 at 17:46
-
I'm decompressing the open xml documents and writing the necessary comments?.xml by myself. I'm also writing the relationships, vmlDrawing docs and adding the legacyDrawing element in sheet?.xml. But when i compress the folder, change its extension to .xlsx and try open it in excel i get a error. – Adones Cunha Oct 21 '08 at 17:53
4 Answers
7
I just did exactly that but with MS Word (using Microsoft.Office.Interop.Word
range.Comments.Add ( range, ref _categoryMessage );
So, I would suggest using Microsoft.Office.Interop.Excel and the similar method. Consider this from MSDN:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.range.addcomment
Also see this too

Gunther Struyf
- 11,158
- 2
- 34
- 58

kenny
- 21,522
- 8
- 49
- 87
-
probably need to play with the editor to get the whole link to work – Lance Roberts Oct 21 '08 at 18:26
-
Thanks, Kenny. But when i do this my program is starting a process called excel. Does it means i need to have ms excel installed on my computer? – Adones Cunha Oct 21 '08 at 20:18
-
-
Something also worth mentioning is that there are no Excel library redistributables when you use the Interop.Excel. So users of the application also need to have Excel installed on their machine. If you need to write the application for targets that don't have Excel installed locally, you need to modify the .xml directly. I believe there are some good utilities for this out there. – Ian Andrews Jan 14 '10 at 15:49
-
For those stumbling on this. Since this answer I've used ClosedXML to create/modify Excel files directly. I'm not 100% they allow access to comments, but highly likely. http://closedxml.codeplex.com/ – kenny Mar 03 '13 at 12:33
-
The actual syntax is: Excel.Range a; a.AddComment("My comment"); – Daniil Shevelev Aug 20 '13 at 19:34
3
The accepted answer points in the right direction, but the correct syntax is:
Excel.Range cell;
cell.AddComment("My comment");

Daniil Shevelev
- 11,739
- 12
- 50
- 73
1
Excel._Worksheet oSheet =
(Microsoft.Office.Interop.Excel._Worksheet) excelWorkbook.ActiveSheet;
oSheet.Cells[2, 3].Cells.AddComment("Selam");

Cihan
- 31
- 3
0
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.

Alexandre Brisebois
- 6,599
- 12
- 50
- 69