Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate cells #217

Open
Tracked by #39
Asbjoedt opened this issue May 8, 2023 · 2 comments
Open
Tracked by #39

Iterate cells #217

Asbjoedt opened this issue May 8, 2023 · 2 comments

Comments

@Asbjoedt
Copy link

Asbjoedt commented May 8, 2023

Hello

I like your toolkit and the OpenDocument format is very easy to understand and save your data in.

I have encountered a problem, whne I try to iterate all cells using the below code:

import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable;
import org.odftoolkit.odfdom.doc.table.OdfTableRow;
import org.odftoolkit.odfdom.doc.table.OdfTableCell;

        OdfSpreadsheetDocument spreadsheet =  OdfSpreadsheetDocument.loadDocument(filepath);
        List<OdfTable> tables = spreadsheet.getSpreadsheetTables();
        for (OdfTable table : tables) {
            List<OdfTableRow> rows = table.getRowList();
            for (OdfTableRow row : rows) {
                List<OdfTableCell> cells = row.getCellList(); // .getCellList() is not recognized
                for (OdfTableCell cell : cells) {
                    // Do something with cell
                }
            }
        }

This code is not recognized row.getCellList();.

Instead if I use this approach, the iteration works, but it does not iterate over an OdfTableCell data type but it iterates a Node data type, which is not what I want:

import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable;
import org.odftoolkit.odfdom.doc.table.OdfTableRow;
import org.odftoolkit.odfdom.doc.table.OdfTableCell;

        OdfSpreadsheetDocument spreadsheet =  OdfSpreadsheetDocument.loadDocument(filepath);
        List<OdfTable> tables = spreadsheet.getSpreadsheetTables();
        for (OdfTable table : tables) {
            List<OdfTableRow> rows = table.getRowList();
            for (OdfTableRow row : rows) {
                NodeList cells = row.getOdfElement().getChildNodes();
                for (int i = 0; i < cells.getLength(); i++) {
                    Node cell = cells.item(i);
                    // Do something with cell
                }
            }
        }

So my question is, why is .getCellList() missing when iterating rows and can it be added to the toolkit?

@mistmist
Copy link
Contributor

mistmist commented May 9, 2023

apparently class OdfTableRow offers only getCellByIndex() and getCellCount(), whereas class OdfTable has getRowByIndex(), getRowCount() and getRowList().

looks like the OdfTable methods were added in 2011 with 0170c73 while OdfTableRow methods are from 2009...

it's not obvious why a getCellList() is missing; it sounds useful, please add it and submit a pull request :)

@svanteschubert
Copy link
Contributor

I second this, a pull request would be most welcome! Thanks in advance! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants