简体   繁体   English

使用Java源代码从MS Excel导入数据

[英]Import Data from MS Excel using Java Source Code

I want to Import data placed in MS Excel and print it using Java Application Program. 我想导入放置在MS Excel中的数据并使用Java应用程序进行打印。 I am newbie in Java. 我是Java的新手。 So Please guide, is it possible. 因此,请指导,是否可能。

If yes, how? 如果是,怎么办? Any website/tutorial will be of great help.. 任何网站/教程都会有很大的帮助。

Thanks in advance.. 提前致谢..

您可以使用POI库读取Excel文件

You can use the jexcel APIs. 您可以使用jexcel API。 They're quite simple overall. 总体而言,它们非常简单。 http://jexcelapi.sourceforge.net/ http://jexcelapi.sourceforge.net/

I also think that Apache POI is working on this area as well. 我还认为Apache POI也正在这一领域工作。

This JSP page connects the Excel sheet to the database . 该JSP页面将Excel工作表连接到数据库。

.<%@ page import="java.sql.*" %><br/>
.<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

<BODY>               

.<%
  Connection con=DriverManager.getConnection("jdbc:odbc:DsnName");<br/>
  Statement stm=con.createStatement();<br/>
  ResultSet rs=stm.executeQuery("select * from [Sheet1$]");       
%>

.<% if(!rs.next()) {
    out.println("Sorry, could not find data");
 }
 else { %>
  .<%=rs.getString(1)%>
.<%}%>

</BODY>

Why not export it from Excel in some format that is not proprietary? 为什么不以非专有格式从Excel导出呢? If the data is not too complex, even CSV might do the trick. 如果数据不太复杂,那么即使CSV也可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM