现在MS Excel在用户中作为数据上传和上报中使用的非常普遍,在java中处理excel是非常简单的要求,但是j2se中没有提供相关的类,Apache POI给我们提供了很好的一个工具。通过他来处理excel非常方便,重要的一点是他是open source的。我在这里简要的据一个demo描述怎样读excel里面的数据。 
import org.apache.poi.hssf.usermodel.*; import java.io.FileInputStream; import org.apache.poi.poifs.filesystem.POIFSFileSystem; 
public class TestPOI { 
public static void main(String[] args) throws Exception{ POIFSFileSystem fs  =  new POIFSFileSystem(new FileInputStream("book1.xls"));  HSSFWorkbook wb = new HSSFWorkbook(fs);  HSSFSheet sheet = wb.getSheetAt(0);  HSSFRow row = sheet.getRow(2);  HSSFCell cell = row.getCell((short)3); String value = cell.getStringCellValue(); System.out.println(" the excel value is " + value); 
} } 
在使用POI的时候觉得有一点不好就是如果单元格的内容是数字,你使用getStringCellValue()的会有异常抛出,所以在用的时候先调用cell.getCellType(),根据cell的类型来调用不同的方法。 
POI的网址在 http://jakarta.apache.org/poi/ 
除了POI外,还有F1 FOR JAVA处理EXCEL,不过他是商业的。功能挺强的,是很强的报表工具,地址在 http://www.reportingengines.com 
还有jexcel也可以处理excel网址在http://threebit.net/projects/jexcel.shtml 
提到处理excel的话,我觉得webofficecomponent不的不提,觉得他是很好的工具,他是M$提供的com控件,在网页中把一个table中的内容显示在excel web控件中间,并且可以直接倒出为excel,demo如下: 
 
 
 
  |