,我用這個方法,因爲事實上,我不能用POI出口問題的java表到excel
public void exportTable(File file)throws IOException{
FileWriter out = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(out);
for(int i = 0; i < myTable.getColumnCount(); i++){
bw.write(myTable.getColumnName(i) + "\t");
}
bw.write("\n");
for(int i = 0; i < myTable.getRowCount(); i++){
for(int j = 0; j < myTable.getColumnCount(); j++){
bw.write(myTable.getValueAt(i, j).toString() +"\t");
}
bw.write("\n");
}
bw.close();
JOptionPane.showMessageDialog(rootPane, "Your table have been exported to " + file);
}
而且我用這個方法與此:
try{
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss");
String desktop = System.getProperty("user.home") + "/Desktop";
String name = desktop + "/MyTable" + dateFormat.format(date)+ ".csv";
exportTable(new File(name));
}catch(IOException e){
e.getMessage();
}
嗯,這是工作不錯,但問題是,在一排每列都被寫在第一列,這一翻譯被寫在不同的專欄中,我認爲「\ t」會解決這個問題,但是,不知道我該如何解決這個問題?
爲了更快得到更好的幫助,請發佈[MCVE]或[簡短,獨立,正確的示例](http://www.sscce.org/)。順便說一句 - 在過去的幾天裏你沒有問過這個問題嗎? –
我發佈了一個類似的問題,但我可以解決這個問題,現在我有一個不同的問題 – Diego
順便說一句 - 得到這個硬編碼數組的工作,它應該爲Swing JTable工作,所以這真的表明這與Swing或JTable無關。我懷疑在刪除的問題上我會提到相同的東西! –