Я изо всех сил пытался получить содержимое из jtable в листе Excel. View - это мой jframe, содержащий jtable. При выполнении действия. Заголовки из jtable только печатают, но не содержимое из него.
public class exporter {
View e=new View();
public void exortTable(JTable table) throws IOException{
TableModel model=e.jtable.getModel();
try {
WritableWorkbook workbook1 = Workbook.createWorkbook(new File("C:\\stu\\hh.xls"));
WritableSheet sheet1 = workbook1.createSheet("First Sheet", 0);
for (int i = 0; i < model.getColumnCount(); i++) {
jxl.write.Label column = new jxl.write.Label(i, 0, model.getColumnName(i));
sheet1.addCell(column);
}
int j = 0;
for (int i = 0; i < model.getRowCount(); i++) {
for (j = 0; j < model.getColumnCount(); j++) {
jxl.write.Label row = new jxl.write.Label (j, i + 1,
model.getValueAt(i, j).toString());
sheet1.addCell(row);
}
}
workbook1.write();
workbook1.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}