2013-08-05 57 views
1

如何从JTable中的.ods文件查看工作表?我使用odftoolkit简单的API,这就是我如何打开文件.ods电子表格到JTable

 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; 
     } 

在这个时候,我得到的每一行与doc.getTableList().get(0).getRowList()。我怎么能把每一行变成数组?

+0

什么类型的'doc.getTableList()。get(0).getRowList()'return?我很确定它提供了一些方法,可以让你制作一个数组。 – MightyPork

+0

他们的API是否有Javadoc?你有没有试过读过它? – Bill

+0

'getRowList()'返回一个'Row'列表,我在'Row'类中找不到有用的方法。也许我很愚蠢,也许不是; D 当然有。不,我刚刚搜索了一下。 – LivingSilver94

回答

2

我怎么能把每一行变成数组?

不要。取而代之的是,使用ODFAPI提供的方法构建实现基本方法的TableModel,如here所示。

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

@Override 
public int getColumnCount() {…} 

@Override 
public int getRowCount() {…} 

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

听起来很复杂。将尝试并报告一些信息:) – LivingSilver94

+1

令人惊叹!有用! – LivingSilver94

相关问题