none
comments did not take effect RRS feed

  • Question

  • Hi ,

    I have generate a xlsx doc with comments , but the comment did not show in the cell

    the following is my xl/comments1.xml file

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <authors>
      <author>yushang</author>
     </authors>
     <commentList>
      <comment ref="B2" authorId="0">
       <text>
        <r>
         <rPr>
          <b val="true"/>
         </rPr>
         <t>TEST</t>
        </r>
        <r>
         <rPr>
          <b val="true"/>
         </rPr>
         <t>TEST</t>
        </r>
       </text>
      </comment>
     </commentList>
    </comments>

    and xl\worksheets\_rels\Sheet1.xml.rels

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="../comments1.xml"/>
    </Relationships>

    did I miss something ?



    • Edited by yushang4 Saturday, June 7, 2014 8:42 AM
    Saturday, June 7, 2014 8:31 AM

Answers

  • Hi,

    How did you generate the xlsx file? I suggest you create a xlxs file add some comment manually and then you rename it with zip. You can compare the difference between the file above and the one gererated by the Excel application. Here is the file generatet by Excel application:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
      <authors>
        <author>Fei Xue (Pactera Technologies)</author>
      </authors>
      <commentList>
        <comment ref="B1" authorId="0" shapeId="0">
          <text>
            <r>
              <rPr>
                <sz val="9"/>
                <color indexed="81"/>
                <rFont val="Tahoma"/>
                <charset val="1"/>
              </rPr>
              <t xml:space="preserve">Hello Word!</t>
            </r>
          </text>
        </comment>
      </commentList>
    </comments>

    Also, if you want to add comments using Open XML, you can open this file with Open XML SDK productivity Tool for Office which shiped with Open XML SDK. You can download this tools from here.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 9, 2014 12:30 PM
    Moderator
  • Hi,

    I suggest you trying to compare the difference between one file before adding comment and the one after adding comment. You will get the difference like figure below:

    If you need to add comment manually, you need to add these changings manually. This forum is for developers discussing issues about Open XML SDK. I suggest you getting support from Office XML, ODF, and Binary File Formats forum, if you want to more detail about Open XML formats.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 12, 2014 7:31 AM
    Moderator

All replies

  • Hi,

    How did you generate the xlsx file? I suggest you create a xlxs file add some comment manually and then you rename it with zip. You can compare the difference between the file above and the one gererated by the Excel application. Here is the file generatet by Excel application:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
      <authors>
        <author>Fei Xue (Pactera Technologies)</author>
      </authors>
      <commentList>
        <comment ref="B1" authorId="0" shapeId="0">
          <text>
            <r>
              <rPr>
                <sz val="9"/>
                <color indexed="81"/>
                <rFont val="Tahoma"/>
                <charset val="1"/>
              </rPr>
              <t xml:space="preserve">Hello Word!</t>
            </r>
          </text>
        </comment>
      </commentList>
    </comments>

    Also, if you want to add comments using Open XML, you can open this file with Open XML SDK productivity Tool for Office which shiped with Open XML SDK. You can download this tools from here.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 9, 2014 12:30 PM
    Moderator
  • Hi ,

    I've downloaded the productivity tools and verified my xlsx doc with it and found no error , but the comment still did not show up !


    • Edited by yushang4 Monday, June 9, 2014 2:34 PM
    Monday, June 9, 2014 2:33 PM
  • Hello,

       You can try following method to add comments.
    // <summary>
        /// Adds all the comments defined in the commentsToAddDict dictionary to the worksheet
        /// </summary>
        /// <param name="worksheetPart">Worksheet Part</param>
        /// <param name="commentsToAddDict">Dictionary of cell references as the key (ie. A1) and the comment text as the value</param>
        public static void InsertComments(WorksheetPart worksheetPart, Dictionary<string, string> commentsToAddDict)
        {
            if (commentsToAddDict.Any())
            {
                string commentsVmlXml = string.Empty;
    
                // Create all the comment VML Shape XML
                foreach (var commentToAdd in commentsToAddDict)
                {
                    commentsVmlXml += GetCommentVMLShapeXML(GetColumnName(commentToAdd.Key), GetRowIndex(commentToAdd.Key).ToString());
                }                       
    
                // The VMLDrawingPart should contain all the definitions for how to draw every comment shape for the worksheet
                VmlDrawingPart vmlDrawingPart = worksheetPart.AddNewPart<VmlDrawingPart>();
                using (XmlTextWriter writer = new XmlTextWriter(vmlDrawingPart.GetStream(FileMode.Create), Encoding.UTF8))
                {
    
                    writer.WriteRaw("<xml xmlns:v=\"urn:schemas-microsoft-com:vml\"\r\n xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n xmlns:x=\"urn:schemas-microsoft-com:office:excel\">\r\n <o:shapelayout v:ext=\"edit\">\r\n  <o:idmap v:ext=\"edit\" data=\"1\"/>\r\n" +
                    "</o:shapelayout><v:shapetype id=\"_x0000_t202\" coordsize=\"21600,21600\" o:spt=\"202\"\r\n  path=\"m,l,21600r21600,l21600,xe\">\r\n  <v:stroke joinstyle=\"miter\"/>\r\n  <v:path gradientshapeok=\"t\" o:connecttype=\"rect\"/>\r\n </v:shapetype>"
                    + commentsVmlXml + "</xml>");
                }
    
                // Create the comment elements
                foreach (var commentToAdd in commentsToAddDict)
                {
                    WorksheetCommentsPart worksheetCommentsPart = worksheetPart.WorksheetCommentsPart ?? worksheetPart.AddNewPart<WorksheetCommentsPart>();                 
    
                    // We only want one legacy drawing element per worksheet for comments
                    if (worksheetPart.Worksheet.Descendants<LegacyDrawing>().SingleOrDefault() == null)
                    {
                        string vmlPartId = worksheetPart.GetIdOfPart(vmlDrawingPart);
                        LegacyDrawing legacyDrawing = new LegacyDrawing() { Id = vmlPartId };
                        worksheetPart.Worksheet.Append(legacyDrawing);
                    }
    
                    Comments comments;
                    bool appendComments = false;
                    if (worksheetPart.WorksheetCommentsPart.Comments != null)
                    {
                        comments = worksheetPart.WorksheetCommentsPart.Comments;
                    }
                    else
                    {
                        comments = new Comments();
                        appendComments = true;
                    }
    
                    // We only want one Author element per Comments element
                    if (worksheetPart.WorksheetCommentsPart.Comments == null)
                    {
                        Authors authors = new Authors();
                        Author author = new Author();
                        author.Text = "Author Name";
                        authors.Append(author);
                        comments.Append(authors);
                    }
    
                    CommentList commentList;
                    bool appendCommentList = false;
                    if (worksheetPart.WorksheetCommentsPart.Comments != null &&
                        worksheetPart.WorksheetCommentsPart.Comments.Descendants<CommentList>().SingleOrDefault() != null)
                    {
                        commentList = worksheetPart.WorksheetCommentsPart.Comments.Descendants<CommentList>().Single();
                    }
                    else
                    {
                        commentList = new CommentList();
                        appendCommentList = true;
                    }
    
                    Comment comment = new Comment() { Reference = commentToAdd.Key, AuthorId = (UInt32Value)0U };
    
                    CommentText commentTextElement = new CommentText();
    
                    Run run = new Run();
    
                    RunProperties runProperties = new RunProperties();
                    Bold bold = new Bold();
                    FontSize fontSize = new FontSize() { Val = 8D };
                    Color color = new Color() { Indexed = (UInt32Value)81U };
                    RunFont runFont = new RunFont() { Val = "Tahoma" };
                    RunPropertyCharSet runPropertyCharSet = new RunPropertyCharSet() { Val = 1 };
    
                    runProperties.Append(bold);
                    runProperties.Append(fontSize);
                    runProperties.Append(color);
                    runProperties.Append(runFont);
                    runProperties.Append(runPropertyCharSet);
                    Text text = new Text();
                    text.Text = commentToAdd.Value;
    
                    run.Append(runProperties);
                    run.Append(text);
    
                    commentTextElement.Append(run);
                    comment.Append(commentTextElement);
                    commentList.Append(comment);
    
                    // Only append the Comment List if this is the first time adding a comment
                    if (appendCommentList)
                    {
                        comments.Append(commentList);
                    }
    
                    // Only append the Comments if this is the first time adding Comments
                    if (appendComments)
                    {
                        worksheetCommentsPart.Comments = comments;
                    }
                }
            }
        }

    -----------------------------------------
     if the reply help you mark it as your answer.
     Free Managed .NET PDF , Excel Word Component(Create, Modify, Convert & Print) 
    Tuesday, June 10, 2014 1:23 AM
  • I'm not using C# to generate the xlsx doc . Could you please tell the pieces missed in the way of OOXML ?many thanks!!!
    Wednesday, June 11, 2014 11:43 PM
  • Hi,

    I suggest you trying to compare the difference between one file before adding comment and the one after adding comment. You will get the difference like figure below:

    If you need to add comment manually, you need to add these changings manually. This forum is for developers discussing issues about Open XML SDK. I suggest you getting support from Office XML, ODF, and Binary File Formats forum, if you want to more detail about Open XML formats.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 12, 2014 7:31 AM
    Moderator