![]() |
#2
rainninghear2010-07-22 20:44
import
import jxl.Cell; import jxl.CellType; import jxl.DateCell; import jxl.NumberCell; import jxl.Sheet; import jxl.Workbook; public class Excel{ public static void main(String args[]) { try { Workbook workbook = null; try { workbook = Workbook.getWorkbook(new File("d://test.xls")); } catch (Exception e) { throw new Exception("file to import not found!"); } Sheet sheet = workbook.getSheet(0); Cell cell = null; int columnCount = 3; int rowCount = sheet.getRows(); for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { // 注意,这里的两个参数,第一个是表示列的,第二才表示行 cell = sheet.getCell(j, i); // 要根据单元格的类型分别做处理,否则格式化过的内容可能会不正确 if (cell.getType() == CellType.NUMBER) { System.out.print(((NumberCell) cell).getValue()); } else if (cell.getType() == CellType.DATE) { System.out.print(((DateCell) cell).getDate()); } else { System.out.print(cell.getContents()); } // System.out.print(cell.getContents()); System.out.print("\t"); } System.out.print("\n"); } // 关闭它,否则会有内存泄露 workbook.close(); } catch (Exception e) { } } } 编译通过后,执行时提示一下错误:请问错在哪里? D:\j>javac Excel.java D:\j>java Excel Exception in thread "main" java.lang.NoClassDefFoundError: jxl/Workbook at Excel.main(Excel.java:16) Caused by: java.lang.ClassNotFoundException: jxl.Workbook at (Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at (Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 1 more |
JSP能否,实现的功能是可选择年,月,根据选择的日期打开相应的excel文件? (excel文件名,以每个月取名如:201007.XSL)
代码如何实现,谢谢!