5

What's the better way to insert cell comments in excel 2007 files programmatically using c# and .net 3.5?

2
  • How are you currently working with the document? Commented Oct 21, 2008 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. Commented Oct 21, 2008 at 17:53

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

6 Comments

probably need to play with the editor to get the whole link to work
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?
Yes. Sorry, these interop calls require Excel.
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.
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. closedxml.codeplex.com
|
3

The accepted answer points in the right direction, but the correct syntax is:

Excel.Range cell; 
cell.AddComment("My comment");

Comments

1
Excel._Worksheet oSheet =
  (Microsoft.Office.Interop.Excel._Worksheet) excelWorkbook.ActiveSheet;
oSheet.Cells[2, 3].Cells.AddComment("Selam");

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.