请问在JAVA中怎样调用MS EXCEL?

zhongyuan 2002-01-09 02:23:54
怎样在JAVA中判断EXCEL是否在运行,如果没有怎样激活EXCEL?
打开EXCEL后怎样调用EXCEL中的操作?
谢谢
...全文
81 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhipop 2002-01-09
  • 打赏
  • 举报
回复
上面的文章需要修改一下,如下:
将forName改为:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
这样就对了
jxta 2002-01-09
  • 打赏
  • 举报
回复
标 题: Java读取Excel数据(转自白云)

发信站: BBS 水木清华站 (Sun Dec 30 19:01:50 2001)



在Java里面,读取Excel里面的数据可以有好几种方法,现在

我利用数据库技术来处理。

Excel在幕种意义上其实就 是一个数据库,所以我们可以按照

Java处理Excel的方式进行处理,当然在处理的过程中要注意几点。

现在我们结合一个例子加以说明。

Step 1: 准备一个Excel File,假如为:baiquan.xsl以及一个DataSheet

为Sample1.

Step 2:建立JDBC数据源,以WinNT为例:步骤是:Start Menu==>Configure

Menu==>Control Panel===>ODBC数据源===>添加(Button)====>选择Excel===>

输入ODBC数据源名字,假定为hust====>选择你在Step 1里面创建的baiquan.xsl

Step 3: Java 代码和注释



//First we shound inport all necessary package

import java.sql.Connection;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.DriverManager;

pubulc class Test

{

public static void main(String[] args)

{

Connection connection=null;

Statement statement=null;

try

{

class.forName("com.jdbc.odbc.JdbcOdbcDriver");

connection=DriverManager.getConnection("jdbc:odbc:hust","","");

// Get Connection , because ODBC DataSource name is "hust",

// Give password and name all are null

statement=connection.createStatement();

// Create Statement

String sql="SELECT * FROM [Sample1$]";

//Note: We suppose DataSheet name is "Sample1" and here

// the table format is "["+DataSheet Name+"$]",There is

// The difference between Excel and Access

ResultSet rs=statement.executeQuery(sql);

System.out.println("Now the Search Result is :");

while(rs.next())

{

System.out.println(rs.getString(1));

}

}

catch(Exception e)

{

System.err.println("Error Message:"+e.toString());

e.printStackTrace();

}

finally

{

try

{

statement.close();

connection.close();

}

catch(Exception e)

{

System.out.println("Close Failed!"+e);

e.printStackTrace();



}

}

}

}

Step 4: Save the File and Compile the run.

以上是基本步骤,可以根据自己的需要进行响应的处理!


不好意思,是转载!前天才看到的!
skyyoung 2002-01-09
  • 打赏
  • 举报
回复
http://www.intrinsyc.com/support/jintegrasuite/index.htm

23,407

社区成员

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

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