///////////////////////////Test.java/////////////////////////////////////////// package com.jagie.test; import java.io.*; import jxl.*; import jxl.write.*; import jxl.format.*; import java.util.*; import java.awt.Color; public class Test{ public static void writeExcel(OutputStream os) throws Exception { jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os); jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0); jxl.write.Label labelC = new jxl.write.Label(0, 0, "我愛中國"); ws.addCell(labelC); jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL,20, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN); jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc); wcfFC.setBackground(jxl.format.Colour.RED); labelC = new jxl.write.Label(6, 0, "中國愛我",wcfFC); ws.addCell(labelC); //寫入Exel工做表 wwb.write(); //關閉Excel工做薄對象 wwb.close(); } //最好寫一個這樣的main方法來測試一下你的這個class是否寫好了。 public static void main(String[] args)throws Exception{ File f=new File("kk.xls"); f.createNewFile(); writeExcel(new FileOutputStream(f)); } } 寫一個jsp,來利用Test這個javabean輸出excel文檔。 ///////////////////////////test_excel.jsp////////////////////////// <%@page import="com.jagie.test.Test" %> <% response.reset(); response.setContentType("application/vnd.ms-excel"); Test.writeExcel(response.getOutputStream()); %>