How do I get the rich text from ODS cell using Simple ODF from ODF Toolkit?

36 views Asked by At

I have a case where a cell has rich text/anchor. I'm trying to get the anchor/href attribute of the cell. I can access the text as follows, using Simple ODF:

InputStream stream = new URL(some"-url-here").openStream();

Row row = SpreadsheetDocument
            .loadDocument(stream)
            .getSheetByIndex(0)
            .getRowIterator()
            .next();

String value = row.getCellByIndex(5).getStringValue();

Here's the library I'm using:

<!-- https://mvnrepository.com/artifact/org.odftoolkit/simple-odf -->
<dependency>
    <groupId>org.odftoolkit</groupId>
    <artifactId>simple-odf</artifactId>
    <version>0.9.0</version>
</dependency>

This returns the text in the cell, but when I open the ODS file with Excel, I see that the cell has a URL/href. I'm looking for a way to get the url.

1

There are 1 answers

0
Hasan Can Saral On BEST ANSWER

I can be done with:

String url = row
    .getCellByIndex(6)
    .getOdfElement()
    .getLastChild()
    .getFirstChild()
    .getAttributes()
    .item(0)
    .getNodeValue();