What's the better way to insert cell comments in excel 2007 files programmatically using c# and .net 3.5?
Insert cell comments in excel programmatically
How are you currently working with the document? –
Opening
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. –
Stonewort
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
probably need to play with the editor to get the whole link to work –
Diorite
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? –
Stonewort
Yes. Sorry, these interop calls require Excel. –
Eructate
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. –
Corticosterone
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 –
Eructate
The actual syntax is: Excel.Range a; a.AddComment("My comment"); –
Secularism
The accepted answer points in the right direction, but the correct syntax is:
Excel.Range cell;
cell.AddComment("My comment");
Excel._Worksheet oSheet =
(Microsoft.Office.Interop.Excel._Worksheet) excelWorkbook.ActiveSheet;
oSheet.Cells[2, 3].Cells.AddComment("Selam");
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.
© 2022 - 2024 — McMap. All rights reserved.