Leitura de arquivos em excel

1 resposta
B

Blz pesoal ?

Esse código abaixo lê algumas tabelas de um arquivo .xls :

import java.sql.*;

public class TestServer

{

static

{

try {

Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);

}

catch (Exception e) {

System.err.println(e);

}

}
public static void main(String args[]) {

Connection conn=null;

Statement stmt=null;

String sql="";

ResultSet rs=null;
try {

conn=DriverManager.getConnection(“jdbc:odbc:excel,"","");

stmt=conn.createStatement();

sql=“select * from [Plan1$];

rs=stmt.executeQuery(sql);
while(rs.next()){

System.out.println(rs.getString(USERID)+

" “+ rs.getString(“FIRST_NAME”)+” "+

rs.getString(LAST_NAME));

}

}

catch (Exception e){

System.err.println(e);

}

finally {

try{

rs.close();

stmt.close();

conn.close();

rs=null;

stmt=null;

conn=null;

}

catch(Exception e){}

}

}

}

O problema é que vou começar a desenvolver um sistema que terá que ler todos arquivos .xls de um diretório e todas tabelas de dentro de cada arquivo (sem que eu saiba o nome das tabelas). Eu gostaria de fazer isso automático , sem eu precisar de ficar criando manualmente um ODBC Data Source pra cada arquivo e sem precisar de abrir cada arquivo pra saber os nomes das tabelas a ler …

Podem me ajudar ?

Obrigado,

Raphael.

1 Resposta

fenrir

Dê uma olhada no POI.

http://jakarta.apache.org/poi/hssf/index.html

Criado 4 de novembro de 2006
Ultima resposta 4 de nov. de 2006
Respostas 1
Participantes 2