Java操作excel文件
http://www.cnblogs.com/wuxinrui/archive/2011/03/20/1989326.html
import java.io.File; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; public class ReadExcel { public static void main(String[] args) { try { //直接从本地文件(.xls)创建Workbook String excelfile = "Book1.xls"; Workbook workbook = Workbook.getWorkbook(new File(excelfile)); //获取第一张Sheet表 Sheet rs = workbook.getSheet(0); //一旦得到了Sheet,就可以通过它来访问Excel Cell(术语:单元格)。 //第三步:访问单元格cell //获取第一行,第一列的值 Cell c00 = rs.getCell(0, 0); String strc00 = c00.getContents(); //获取第一行,第二列的值 Cell c10 = rs.getCell(1, 0); String strc10 = c10.getContents(); //获取第二行,第二列的值 Cell c11 = rs.getCell(1, 1); String strc11 = c11.getContents(); System.out.println("Cell(0, 0)" + " value : " + strc00 + "; type : " + c00.getType()); System.out.println("Cell(1, 0)" + " value : " + strc10 + "; type : " + c10.getType()); System.out.println("Cell(1, 1)" + " value : " + strc11 + "; type : " + c11.getType()); // 获取第四行,第一列的值 Cell c03 = rs.getCell(0,3); System.out.println("第四行,第一列的值:"+c03.getContents()); String contents = rs.getCell(0,4).getContents(); // 得到的是空字符串 System.out.println("第五行,第一列的值:"+contents); String s44 = rs.getCell(3, 3).getContents(); System.out.println(s44); } catch (Exception e) { e.printStackTrace(); } } }