.ods spreadsheet to JTable

346 views Asked by At

How can I view a sheet from .ods file in JTable? I'm using odftoolkit simple api and that's how I open the file

      String filepath;
      if (openfile.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        filepath = openfile.getSelectedFile().getAbsolutePath();
        try {
            doc = SpreadsheetDocument.loadDocument(filepath);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,
                    Locale.getString("fileError.message"),
                    Locale.getString("fileError.title"),
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

At this time I get every row with doc.getTableList().get(0).getRowList(). How could I turn every row into array?

1

There are 1 answers

1
trashgod On BEST ANSWER

How could I turn every row into array?

Don't. Instead, build a TableModel that implements the essential methods, as shown here, using the methods provided by the ODF API.

@Override
public String getColumnName(int col) {…}

@Override
public int getColumnCount() {…}

@Override
public int getRowCount() {…}

@Override
public Object getValueAt(int row, int col) {…}