1个回答
展开全部
核心代码如下,自己多试试看,不难的
try {
String excelFileName="myTable.xls";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
excelFileName = "myAuthors.xls";
excelDatabase= "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=";
excelDatabase+= excelFileName.trim() + ";DriverID=278;READONLY=false}";
excelCon = DriverManager.getConnection(excelDatabase,"","");
if(!excelCon.isClosed())
System.out.println("Successfully Connected To Excel !!");
Statement excelStat;
excelStat=excelCon.createStatement();
for(rowI=0;rowI<table.getRowCount();rowI++)
{
sqlInsert="Insert into `Sheet1$` values("+table.getValueAt(rowI,0))+","+table.getValueAt(rowI,1)+")";
excelStat.executeUpdate(sqlInsert);
}
try {
String excelFileName="myTable.xls";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
excelFileName = "myAuthors.xls";
excelDatabase= "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=";
excelDatabase+= excelFileName.trim() + ";DriverID=278;READONLY=false}";
excelCon = DriverManager.getConnection(excelDatabase,"","");
if(!excelCon.isClosed())
System.out.println("Successfully Connected To Excel !!");
Statement excelStat;
excelStat=excelCon.createStatement();
for(rowI=0;rowI<table.getRowCount();rowI++)
{
sqlInsert="Insert into `Sheet1$` values("+table.getValueAt(rowI,0))+","+table.getValueAt(rowI,1)+")";
excelStat.executeUpdate(sqlInsert);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询