i want export data on 'jtable' excel file , when export successful massage dialog box displayed , user can ether choose open saved file or not. have figured out how save file. i'm not sure how open file saved. in order believe these 2 lines need fixed.
desktop dt = desktop.getdesktop(); dt.open(new file(this.file));
below coding far.
private void exportbuttonactionperformed(java.awt.event.actionevent evt) { try{ jfilechooser fc = new jfilechooser(); int option = fc.showsavedialog(searchgui.this); if(option == jfilechooser.approve_option){ try{ string filename = fc.getselectedfile().getname(); string path = fc.getselectedfile().getparentfile().getpath(); int len = filename.length(); string ext = ""; string file = ""; if(len > 4){ ext = filename.substring(len-4, len); } if(ext.equals(".xls")){ file = path + "\\" + filename; }else{ file = path + "\\" + filename + ".xls"; } toexcel(phonebook, new file(file)); int answer = joptionpane.showconfirmdialog(null, "would open exported file?", "successfully exported!", option); if (answer == joptionpane.yes_option) { try { desktop dt = desktop.getdesktop(); dt.open(new file(this.file)); } catch (exception e ){ joptionpane.showmessagedialog(null, e); } } }catch(exception e){ joptionpane.showmessagedialog(null, e); } } } catch(exception e){ joptionpane.showmessagedialog(null, e); } }
please help!!
caught error should be
desktop dt = desktop.getdesktop(); dt.open(new file(file));
instead of
desktop dt = desktop.getdesktop(); dt.open(new file(this.file));
Comments
Post a Comment