当前位置: 技术问答>java相关
java如何将JTable内容写入excel文件
来源: 互联网 发布时间:2015-08-03
本文导语: 谢谢。 | import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import com.util.*; import java.util.*; import javax.swing.table.*; import java.sql.*; public class TestDatabase extends JApplet { bo...
谢谢。
|
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.util.*;
import java.util.*;
import javax.swing.table.*;
import java.sql.*;
public class TestDatabase extends JApplet {
boolean isStandalone = false;
JButton jButton1 = new JButton(); //触发时间查询按扭
Database db=new Database();
JTable table1 = new JTable();
JScrollPane scroll = new JScrollPane();
JTextField text1 = new JTextField();
DefaultTableModel dtm; //定义表格的数据模型
Vector vCdata=null; //定义表的列名(以vector存储)
ResultSet rsRow=null; //查询表的数据集合
/**Construct the applet*/
public TestDatabase() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
userInit(); //自定义的操作都在次方法中
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(26, 225, 79, 29));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
this.setSize(new Dimension(664, 300));
this.getContentPane().setLayout(null);
scroll.setBounds(new Rectangle(12, 24, 644, 189));
text1.setBounds(new Rectangle(16, 271, 365, 22));
this.getContentPane().add(scroll, null);
this.getContentPane().add(jButton1, null);
// this.getContentPane().add(text1, null);
scroll.getViewport().add(table1, null);
}
/*userInit() 数据表格的初始化*/
public void userInit()
{
db.connect(); //数据库连接
vCdata=db.getFieldNames("T_REGISTRATION"); //得出列名(vector存储)
dtm=new DefaultTableModel(); //定义模式
table1.setModel(dtm); //设定表模式
/**for 列出标题烂**/
for(int i=0;i
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.util.*;
import java.util.*;
import javax.swing.table.*;
import java.sql.*;
public class TestDatabase extends JApplet {
boolean isStandalone = false;
JButton jButton1 = new JButton(); //触发时间查询按扭
Database db=new Database();
JTable table1 = new JTable();
JScrollPane scroll = new JScrollPane();
JTextField text1 = new JTextField();
DefaultTableModel dtm; //定义表格的数据模型
Vector vCdata=null; //定义表的列名(以vector存储)
ResultSet rsRow=null; //查询表的数据集合
/**Construct the applet*/
public TestDatabase() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
userInit(); //自定义的操作都在次方法中
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(26, 225, 79, 29));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
this.setSize(new Dimension(664, 300));
this.getContentPane().setLayout(null);
scroll.setBounds(new Rectangle(12, 24, 644, 189));
text1.setBounds(new Rectangle(16, 271, 365, 22));
this.getContentPane().add(scroll, null);
this.getContentPane().add(jButton1, null);
// this.getContentPane().add(text1, null);
scroll.getViewport().add(table1, null);
}
/*userInit() 数据表格的初始化*/
public void userInit()
{
db.connect(); //数据库连接
vCdata=db.getFieldNames("T_REGISTRATION"); //得出列名(vector存储)
dtm=new DefaultTableModel(); //定义模式
table1.setModel(dtm); //设定表模式
/**for 列出标题烂**/
for(int i=0;i