Saving JTable as text file

后端 未结 4 1251
星月不相逢
星月不相逢 2021-01-03 17:14

I am saving a .txt and .doc file containing the data from my JTable. At the minute when it saves it lays the text out like its in a table, but due to different lengths of da

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 17:42

    The algorithm is quite simple:

    for (int row = 0; row < table.getRowCount(); row++) {
        for (int col = 0; col < table.getColumnCount(); col++) {
            os.print(table.getColumnName(col));
            os.print(": ");
            os.println(table.getValueAt(row, col));
        }
    }
    

提交回复
热议问题