We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to extract comments text from XLSX file in Java

Hi,
I can extract text from excel include comment text using Aspose.Cell, but there are always more text in the extracted comment text.

here is my code:

CommentCollection comments = workbook.getWorksheets().get(sheetIndex).getComments();
StringBuilder commentBuilder = new StringBuilder();
if (comments != null && comments.getCount() > 0) {
    for (int i = 0; i < comments.getCount(); i++) {
        Comment comment = comments.get(i);
       commentBuilder.append(comment.getNote());
   }
}

my excel file and result file:testfile.zip (56.1 KB)

@lucy.hq,

I used the following sample code with latest version of Aspose.Cells for Java v21.9 and it works fine:
e.g.
Sample code:

Workbook workbook = new Workbook("f:\\files\\file_example_XLSX_100.xlsx");
        //CommentCollection comments = workbook.getWorksheets().get(sheetIndex).getComments();
        CommentCollection comments = workbook.getWorksheets().get(0).getComments();
        StringBuilder commentBuilder = new StringBuilder();
        if (comments != null && comments.getCount() > 0) {
            for (int i = 0; i < comments.getCount(); i++) {
                Comment comment = comments.get(i);
                commentBuilder.append(comment.getNote());
            }

            System.out.println(commentBuilder.toString());
        }

output:

Lucy Hao:
test1111[线程批注]

你的Excel版本可读取此线程批注; 但如果在更新版本的Excel中打开文件,则对批注所作的任何改动都将被删除。了解详细信息: https://go.microsoft.com/fwlink/?linkid=870924

注释:
test222

See the attached screenshot which shows what comment text MS Excel shows.
sc_shot1.png (67.5 KB)

Please try using our latest version/fix and in case, you still find any issue, kindly elaborate more with details and sample and do highlight the issue in screenshot, we will check it soon.

Why can’t I see these word like “[线程标注]”? here is my excel screenshottest.png (77.7 KB)

@lucy.hq,

Are you using office 365 for Excel? Please try using MS Excel 2013, 2016, etc. and let us know if are not seeing those text. I am using MS Excel 2007 and 2016 and I can view it.

@lucy.hq,
If the comment is a threaded comment, please try the following codes:
CommentCollection comments = workbook.getWorksheets().get(0).getComments();
StringBuilder commentBuilder = new StringBuilder();
if (comments != null && comments.getCount() > 0) {
for (int i = 0; i < comments.getCount(); i++) {
Comment comment = comments.get(i);
ThreadedCommentCollection threadeadComments = comment.getThreadedComments();
if(threadeadComments.getCount() > 0)
{
for (int j = 0; j < threadeadComments.getCount(); j++)
{
ThreadedComment tc = threadeadComments.get(j);
commentBuilder.append(tc.getNotes());
}
}else
{
commentBuilder.append(comment.getNote());
}

	    }
	 }

BTW, we will add Comment.IsThreadedComment() method to check whether it’s a thread comment.

Thank you so much for so detailed support. I’m afraid of we need to wait you to add Comment.IsThreadedComment() method, because excel file aren’t made by us, we don’t know whether there is thread comment. Can you please update us once you add this method?

@lucy.hq,

The attribute is already added in newer versions. Please try our latest version/fix (Aspose.Cells for Java v21.9.4).
aspose-cells-21.9.4-java.zip (7.4 MB)

1 Like

Does 21.9.4 publish to https://repository.aspose.com/repo/? I can’t get it from repository. Or does comment.getThreadedComments().getCount work same as IsThreadedComment method?

@lucy.hq,

We are scheduled to publish our next official version (Aspose.Cells for Java v21.10) within a couple of days. This new version also includes all the enhancements plus fixes of older versions and fixes (including 21.9.4).

Please get/download the new version from the repos. when it will be released.

PS. only official releases are published to Aspose repos. or Downloads section.

Thank you, maybe we need to wait for 21.10. Does comment.getThreadedComments().getCount work same as IsThreadedComment method?

@lucy.hq,

Yes, it should work. If not, then you may try the new version (which is going to be published in a couple of days).

comment.getThreadedComments().getCount works fine, thank you very much

@lucy.hq,
Good to know that your issue is sorted out. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

@lucy.hq,

Moreover, we have published our next official release (Aspose.Cells for Java v21.10) of the product, so you may get it from Downloads/Maven repos.