I think the library you are using (POI) is the best for your purposes. Sometimes the problem may be in a non-optimized code or in using an outdated version of the library, the latest version is September 2016 .
Anyway:
Excel as Database
In Java you can read Excel sheets as if you were accessing a Database.
For this you need to add the JDBC ODBC drivers to your project.
I leave you an example code, published in Java2s .
It is assumed in the example that you have a sheet called Sheet1
and in that sheet you have columns called FirstName
, LastName
. Queries as if it were a database, you get a rs
and you operate with the returned values.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Main {
public static Connection getConnection() throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:excelDB";
String username = "yourName";
String password = "yourPass";
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
public static void main(String args[]) throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
conn = getConnection();
stmt = conn.createStatement();
String excelQuery = "select * from [Sheet1$]";
rs = stmt.executeQuery(excelQuery);
while (rs.next()) {
System.out.println(rs.getString("FirstName") + " " + rs.getString("LastName"));
}
rs.close();
stmt.close();
conn.close();
}
}
Other bookstores
There are also these libraries:
JXLS
JExcelApi (looks a little old).