各位大侠,有jsp数据导入Excel的资料吗

spidercrow 2004-10-09 09:59:41
各位大侠请帮帮小弟啦!
...全文
152 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rongcolt 2004-10-09
  • 打赏
  • 举报
回复
不用他的,自己做,很简单!
import java.sql.*;
public class TestExcel {
public TestExcel() throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:driver={Microsoft Excel Driver (*.xls)};DBQ=d:\\data\\mlb.xls";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
String sSql;
sSql = "select * from [Sheet1$]";
ResultSet rs = stmt.executeQuery(sSql);
ResultSetMetaData meta=rs.getMetaData();
int col=meta.getColumnCount();
System.out.println("共"+col+"列");
for(int i=1;i<=col;i++){
System.out.println("第"+i+"列:"+meta.getColumnName(i)+"||类型:"+meta.getColumnType(i)+"||类型名:"+meta.getColumnTypeName(i));
}
while(rs.next()){
System.out.println(rs.getString(3)+"|"+rs.getString(5));
}
rs.getStatement().close();
stmt.close();
conn.close();
}
public static void main(String s[]) throws Exception{
new TestExcel();
}
}
yujiabian 2004-10-09
  • 打赏
  • 举报
回复
你可以下载jxl.jar,然后使用该组件来开发
loverface 2004-10-09
  • 打赏
  • 举报
回复
收藏
spidercrow 2004-10-09
  • 打赏
  • 举报
回复
谢谢还是不太明白!
hbwjz 2004-10-09
  • 打赏
  • 举报
回复
使用韩国那个程序员开发的jxl,很好使的
HuangQQ 2004-10-09
  • 打赏
  • 举报
回复
try{
InputStream books1 = new FileInputStream(FilePath);
jxl.Workbook rwb = Workbook.getWorkbook(books1);
Sheet rs = rwb.getSheet(0);

//取得行数
int rsColumns = rs.getColumns();
//取得列数
int rsRows = rs.getRows();
String ErrorMsgeS[] = new String[rsRows];
//out.print(rsColumns);
//out.print(rsRows);

int i,j,k;
String strCell[][] = new String[rsRows][rsColumns];
for (i=1;i<rsRows;i++){
for(j=0;j<rsColumns;j++){
//行列是调过来的
Cell c00 = rs.getCell(j,i);
strCell[i][j] = c00.getContents();
}
}
}catch(Exception e){}

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧