急!用IBM的类库读excel文件!
从网上下载了IBM的包,但参考资料不足,那为大哥熟悉或者有相关例子?我给200分,决不食言
public class test
{
public static void main(String[] argv)
{
com.ibm.excelaccessor.ExcelWorkbook workbook=new com.ibm.excelaccessor.ExcelWorkbook();
workbook.setWorkbookName(new java.lang.String("1.xls"));
workbook.setReadOnly(false);
workbook.openWorkbook();
System.out.println("Worksheetes:");
String[] ws=workbook.getWorksheets();
com.ibm.excelaccessor.ExcelRange range=new com.ibm.excelaccessor.ExcelRange();
range.setXlWorkbook(workbook);
if(ws!=null){
for(int i = 0;i < ws.length;i++){
System.out.println("Sheet:" + ws[i]);
range.setWorksheetName(ws[i]);
range.setAutoGetUsedRange(true);
range.setAutoCreateSheet(false);
range.initRange();
java.util.Vector dd = range.getText();
for(int j = 0;j < dd.size();j++){
Object xx[] = (Object[])(dd.get(j));
for(int k = 0;k < xx.length;k++)
System.out.print("" + j + ":" + k + "!" + xx[k]);
System.out.print("\n");
}
}
}
}
}
问题点数:100、回复次数:7Top
1 楼hotenM(南京)回复于 2002-10-19 18:07:08 得分 0
我以前也读写过excel,不过不是用ibm包的,
用的一个东西叫jxl.jar,里面带例子,你可以去搜索下一下,也可以给我mail,我告诉你
很好用Top
2 楼lanying(蓝鹰)(问个不休)回复于 2002-10-19 18:14:24 得分 0
wzw888@263.net
多谢了,200分绝不试验
Top
3 楼lanying(蓝鹰)(问个不休)回复于 2002-10-19 18:31:26 得分 0
靠!IBM的只能读,写windows下的
谁有能读写unix下excel文件的文档,包,例子下载?Top
4 楼hotenM(南京)回复于 2002-10-19 18:43:42 得分 0
发了,我的邮件是jiangyz@hoten.com
记得给分Top
5 楼lanying(蓝鹰)(问个不休)回复于 2002-10-19 19:21:38 得分 0
什么呀,不行,读不了
连他自带的例子也运行不了Top
6 楼hotenM(南京)回复于 2002-10-19 19:24:51 得分 0
那一定,我的可以运行的,而且运行在我的一套系统上(linux上的)
你运行不肯定是你设置的不对Top
7 楼hotenM(南京)回复于 2002-10-19 19:26:29 得分 100
import java.io.File;
import java.util.Date;
import jxl.*;
...
Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));
(NOTE: when creating a spreadsheet from a ServletInputStream you must remove the HTTP header information before creating the Workbook object.)
Once you have accessed the workbook, you can use this to access the individual sheets. These are zero indexed - the first sheet being 0, the second sheet being 1, and so on. (You can also use the API to retrieve a sheet by name).
Sheet sheet = workbook.getSheet(0);
Once you have a sheet, you can then start accessing the cells. You can retrieve the cell's contents as a string by using the convenience method getContents(). In the example code below, A1 is a text cell, B2 is numerical value and C2 is a date. The contents of these cells may be accessed as follows
Cell a1 = sheet.getCell(0,0);
Cell b2 = sheet.getCell(1,1);
Cell c2 = sheet.getCell(2,1);
String stringa1 = a1.getContents();
String stringb2 = b2.getContents();
String stringc2 = c2.getContents();
这不是里面的例子吗?你把jxl.jar放在你的classpath下再试试吧,用java程序。
肯定可以的,只要java可以jsp就可以,因为jsp里面就是java代码Top




