怎么在JAVA程序中设置一个按钮 当点击该按钮时打开(启动)Excel电子表格
最好附代码 并有详细的解释
拜托大家 不胜感激
最好附代码 并有详细的解释
拜托大家 不胜感激
解决方案 »
- 亟待解决I/O Error: Socket closed,在此谢过
- 如何解决jsp未即时编译而产生500错误页面的问题?
- 如何通过ajax实现文本框自动补全功能?
- struts-config.xml加载错误-No action config found for the specified url?
- 关于APACHE的MINA框架的问题!!!!!!!!
- 求助:EJB-QL语句实现插入记录
- JMX高手请进:(高分送出)
- struts标签问题
- mapping configuration error for request uri /operatorservlet
- 在webshere中成功配置了oracle jndi名称为什么还找不到类工厂,已经放在指定路径并且是classes12.zip/classes12.jar
- google API 能帮下吗?
- 困扰好几天的问题,请大家帮忙解决下,谢谢!
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;public class ButtonFrame extends JFrame{ private JPanel infoPanel = new JPanel();
public ButtonFrame() {
this.setTitle("Web Service");
this.setSize(400, 200);
this.add(getInfoPanel());
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private JPanel getInfoPanel() {
if(infoPanel == null){
infoPanel = new JPanel();
}
JLabel nameLabel = new JLabel("Click!");
infoPanel.add(nameLabel);
JButton commitButton = new JButton("Start");
commitButton.addActionListener(new
ActionListener(){ public void actionPerformed(ActionEvent arg0) {
try {
//这里填你的excel文件名
openExcel("f:\\1.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
});
infoPanel.add(commitButton);
return infoPanel;
} /**
* open file
* @param excelFileName
* @throws IOException
*/
public void openExcel(String excelFileName) throws IOException {
FileWriter writer = new FileWriter( "c:\\mysql.bat");
writer.write(excelFileName);
writer.close();
String command = excelFileName;
try {
Process child = Runtime.getRuntime().exec("c:\\mysql.bat");
} catch (IOException e) {
System.out.println("Process error!");
e.printStackTrace();
}
}
public static void main(String[] args) {
ButtonFrame frame = new ButtonFrame();
}
}