简体   繁体   中英

Set html in Comment in excel using Aspose.Cells

I am working n exporting excel using Aspose.Cells . In that i need to show some HTML formatted comment in specific column. But when i set note in comment using HTML string then it automatically modify that HTML . I am usiing below code

Workbook workbook = GetExcelWorkbook<AuditLogExport>(auditLogExportData, templatePath);
        CommentCollection comments = workbook.Worksheets[0].Comments;
        for (int i = 0; i < exportData.Count; i++)
        {
            if (exportData[i].IsDetailedChange)
            {
                int commentIndex = comments.Add(string.Format("E{0}", (i + 2)));
                Aspose.Cells.Comment comment = comments[commentIndex];
                **comment.HtmlNote = GetAuditLogCommentNote(exportData[i]);**
                comment.WidthCM = 8.0;
                comment.HeightCM = 20.0;
            }
        }


public static string GetAuditLogCommentNote(AuditLog auditLog)
    {
        string note = string.Empty;
        note = "<table width='400px' style='border:solid 1px black'><tr><th>Changed Field</th><th>Previous</th><th>Current</th></tr>";
        foreach (var history in auditLog.DetailChanges)
        {
            note += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", history.FieldName, history.FirstChange, history.LastChange);
        }
        note += "</table>";

        return note;
    }

When i am assigning value to HtmlNote property of comment it automatically change html with font tags and strip all table tags from string. Can someone please help on this?

Update-1

Well, we think, your requirement is not achievable using Microsoft Excel. If something is not possible with Microsoft Excel, then it will also not be possible with Aspose.Cells or any other API automatically.

Please see the following screenshot. It shows how your HTML looks like when it is viewed in Web Browser and when it is copied/pasted to Excel comment.

在此处输入图片说明

If you think, your requirement is doable using Microsoft Excel, please provide us your sample Excel file that you have created manually using Microsoft Excel. We will check it and investigate this issue further.


Update-2

We tested this issue with the following code and found that if we try to create comment with HtmlNote property, it does not work.

We have logged this issue in our database for investigation and for a fix. Once, the issue is resolved, we will update you in this post.

This issue has been logged as

  • CELLSNET-46210 - Creating Comment using HtmlNote property does not work

C#

Workbook wb = new Workbook();

Worksheet ws = wb.Worksheets[0];

int idx = ws.Comments.Add("E4");
Comment cm = ws.Comments[idx];
//cm.HtmlNote = "<Font Style=\"FONT-WEIGHT: bold;FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\">Heading: </Font><Font Style=\"FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\">This is some para. </Font><Font Style=\"FONT-WEIGHT: bold;FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\">Heading2:</Font><Font Style=\"FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\"> This is some para2.</Font>";
cm.HtmlNote = new Workbook("input.xlsx").Worksheets[0].Comments[0].HtmlNote;
cm.IsVisible = true;

wb.Save("output.xlsx");

Update-3

Your issue logged as CELLSNET-46210 has been fixed in Aspose.Cells for .NET v18.7. Please download it from this link.

https://www.nuget.org/packages/Aspose.Cells/18.7.0


Note: I am working as Developer Advocate at Aspose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM