以编程方式使用Open XML插入WorkSheet注释 - “......不可读的内容......”

时间:2013-12-16 07:06:10

标签: c# asp.net openxml openxml-sdk

我试图通过c#代码添加评论后动态添加excel评论并尝试打开显示错误dilaog框的xlsx电子表格 “Excel在bulkupload.xlsx中找到了不可读的内容。你想......”显示,如果Clik是,那么它就不会出现评论 请帮助任何人。

我的示例代码

private static void GenerateWorksheetCommentsPart1Content(WorksheetCommentsPart worksheetCommentsPart1)
    {
        Comments comments1 = new Comments();

        Authors authors1 = new Authors();
        Author author1 = new Author();
        author1.Text = "Geny";
        Author author2 = new Author();
        author2.Text = "rose";

        authors1.Append(author1);
        authors1.Append(author2);

        CommentList commentList1 = new CommentList();

        Comment comment1 = new Comment() { Reference = "B2", AuthorId = (UInt32Value)0U };

        CommentText commentText1 = new CommentText();

        Run run1 = new Run();

        RunProperties runProperties1 = new RunProperties();
        Bold bold1 = new Bold();
        FontSize fontSize1 = new FontSize() { Val = 9D };
        Color color1 = new Color() { Indexed = (UInt32Value)81U };
        RunFont runFont1 = new RunFont() { Val = "Tahoma" };
        FontFamily fontFamily1 = new FontFamily() { Val = 2 };

        runProperties1.Append(bold1);
        runProperties1.Append(fontSize1);
        runProperties1.Append(color1);
        runProperties1.Append(runFont1);
        runProperties1.Append(fontFamily1);
        Text text1 = new Text();
        text1.Text = "add comment 1";

        run1.Append(runProperties1);
        run1.Append(text1);

        commentText1.Append(run1);

        comment1.Append(commentText1);


        Comment comment2 = new Comment() { Reference = "B7", AuthorId = (UInt32Value)1U };


        CommentText commentText2 = new CommentText();

        Run run2 = new Run();

        RunProperties runProperties2 = new RunProperties();
        Bold bold2 = new Bold();
        FontSize fontSize2 = new FontSize() { Val = 8D };
        Color color2 = new Color() { Indexed = (UInt32Value)81U };
        RunFont runFont2 = new RunFont() { Val = "Tahoma" };
        RunPropertyCharSet runPropertyCharSet1 = new RunPropertyCharSet() { Val = 1 };

        runProperties2.Append(bold2);
        runProperties2.Append(fontSize2);
        runProperties2.Append(color2);
        runProperties2.Append(runFont2);
        runProperties2.Append(runPropertyCharSet1);
        Text text2 = new Text();
        text2.Text = "add second comment";

        run2.Append(runProperties2);
        run2.Append(text2);

        Run run3 = new Run();

        RunProperties runProperties3 = new RunProperties();
        FontSize fontSize3 = new FontSize() { Val = 8D };
        Color color3 = new Color() { Indexed = (UInt32Value)81U };
        RunFont runFont3 = new RunFont() { Val = "Tahoma" };
        RunPropertyCharSet runPropertyCharSet2 = new RunPropertyCharSet() { Val = 1 };

        runProperties3.Append(fontSize3);
        runProperties3.Append(color3);
        runProperties3.Append(runFont3);
        runProperties3.Append(runPropertyCharSet2);
        Text text3 = new Text() { Space = SpaceProcessingModeValues.Preserve };
        text3.Text = "\ntested";

        run3.Append(runProperties3);
        run3.Append(text3);

        commentText2.Append(run2);
        commentText2.Append(run3);

        comment2.Append(commentText2);

        commentList1.Append(comment1);
        commentList1.Append(comment2);

        comments1.Append(authors1);

        comments1.Append(commentList1);

        worksheetCommentsPart1.Comments = comments1;
    }

0 个答案:

没有答案