Click here to Skip to main content
15,886,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a requirement in my project to read comments in an excel document and process those comments.

I am using Open XML approach to do this.
Can anyone suggest a way to achieve this ?

Thanks and Regards,
YKK Reddy
Posted

Hi,

i solved using the below mentioned code.

SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(/* Excel File Name */, true);

XML
WorkbookPart workBookPart = spreadSheetDocument.WorkbookPart;
List<string> lstComments = new List<string>();
foreach (WorksheetPart sheet in workBookPart.WorksheetParts)
{
    foreach (WorksheetCommentsPart commentsPart in sheet.GetPartsOfType<WorksheetCommentsPart>())
    {
        foreach (Comment comment in commentsPart.Comments.CommentList)
        {
            lstComments.Add(comment.InnerText);
        }
    }
}




lstComments contains the Comments present in all the sheets. We can further refine it for a particular sheet also.

Thanks and Regards,
Kishor Reddy
 
Share this answer
 
v2
 
Share this answer
 
v2
Comments
[no name] 25-Jan-12 4:03am    
The above links deals with retrieving the cell values. But i need the comments assigned to a particular cell.

Can you post a sample code regarding the same.

Thanks in Advance,
YKK Reddy
ambarishtv 25-Jan-12 4:23am    
Hi ..i updated solution
[no name] 25-Jan-12 6:17am    
Hi,

In all the above mentioned links source is mentioned related to retrieving data/values from the excel cells OR setting values to excel cells.
What i wanted is if there are any comments attached to the excel cells, i need the list of all the comments along with the cell numbers (Eg, A1, D4 etc).

Is it possible using OpenXML SDK ?

Thanks in Advance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900