JAVA EXCEL API:是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容、创建新的Excel文件、更新已经存在的Excel文件。使用该API非Windows操作系统也可以通过纯Java应用来处理Excel数据表。因为它是使用Java编写的,所以我们在Web应用中可以通过JSP、Servlet来调用API实现对Excel数据表的访问。
  下载:
  官方网站http://www.andykhan.com/jexcelapi/下载新版本(本人下的是jexcelapi_2_6_12.tar.gz,解压后将里面的jxl.jar复制到WEB-INF/lib目录下面即可)
  Java Excel API的jar包可以通过以下URL获得:
  http://sourceforge.net/projects/jexcelapi/files/jexcelapi/2.6.6/jexcelapi_2_6_6.zip/download
  (包括所有版本):http://sourceforge.net/projects/jexcelapi/files/
  直接下载地址(迅雷上新建任务即可):
  http://nchc.dl.sourceforge.net/project/jexcelapi/jexcelapi/2.6.6/jexcelapi_2_6_6.zip
  一、JSP生成简单的Excel文件
  package beans.excel;
  import java.io.IOException;
  import java.io.OutputStream;
  import jxl.Workbook;
  import jxl.write.Label;
  import jxl.write.WritableSheet;
  import jxl.write.WritableWorkbook;
  import jxl.write.WriteException;
  public class SimpleExcelWrite {
  public void createExcel(OutputStream os) throws WriteException,IOException{
  //创建工作薄
  WritableWorkbook workbook = Workbook.createWorkbook(os);
  //创建新的一页
  WritableSheet sheet = workbook.createSheet("First Sheet",0);
  //创建要显示的内容,创建一个单元格,第一个参数为列坐标,第二个参数为行坐标,第三个参数为内容
  Label xuexiao = new Label(0,0,"学校");
  sheet.addCell(xuexiao);
  Label zhuanye = new Label(1,0,"专业");
  sheet.addCell(zhuanye);
  Label jingzhengli = new Label(2,0,"专业竞争力");
  sheet.addCell(jingzhengli);
  Label qinghua = new Label(0,1,"清华大学");
  sheet.addCell(qinghua);
  Label jisuanji = new Label(1,1,"计算机专业");
  sheet.addCell(jisuanji);
  Label gao = new Label(2,1,"高");
  sheet.addCell(gao);
  Label beida = new Label(0,2,"北京大学");
  sheet.addCell(beida);
  Label falv = new Label(1,2,"法律专业");
  sheet.addCell(falv);
  Label zhong = new Label(2,2,"中");
  sheet.addCell(zhong);
  Label ligong = new Label(0,3,"北京理工大学");
  sheet.addCell(ligong);
  Label hangkong = new Label(1,3,"航空专业");
  sheet.addCell(hangkong);
  Label di = new Label(2,3,"低");
  sheet.addCell(di);
  //把创建的内容写入到输出流中,并关闭输出流
  workbook.write();
  workbook.close();
  os.close();
  }
  }
  SimpleExcelWrite.jsp
  <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
  <%@ page import="java.io.*" %>
  <%@ page import="beans.excel.*" %>
  <%
  String fname = "学校竞争力情况";
  OutputStream os = response.getOutputStream();//取得输出流
  response.reset();//清空输出流
  //下面是对中文文件名的处理
  response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式
  fname = java.net.URLEncoder.encode(fname,"UTF-8");
  response.setHeader("Content-Disposition","attachment;filename="+new String(fname.getBytes("UTF-8"),"GBK")+".xls");
  response.setContentType("application/msexcel");//定义输出类型
  SimpleExcelWrite sw = new SimpleExcelWrite();
  sw.createExcel(os);
  %>
  <html>
  <head>
  <title></title>
  </head>
  <body>
  </body>
  </html>