gavin.yu 发表于 2013-1-15 02:58:09

JAVA EXCEL API(jxl)简介

Java Excel是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容、创建新的Excel文件、更新已经存在的Excel文件。使用该 API非Windows操作系统也可以通过纯Java应用来处理Excel数据表。因为是使用Java编写的,所以我们在Web应用中可以通过JSP、 Servlet来调用API实现对Excel数据表的访问。
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif提供以下功能:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 从Excel 95、97、2000等格式的文件中读取数据;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 读取Excel公式(可以读取Excel 97以后的公式);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 生成Excel数据表(格式为Excel 97);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 支持字体、数字、日期的格式化;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 支持单元格的阴影操作,以及颜色操作;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 修改已经存在的数据表;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif    * 能够读取图表信息 
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif1.应用示例:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif包括从Excel读取数据,生成新的Excel,以及修改Excel
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifpackage common.util;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport jxl.*;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport jxl.format.UnderlineStyle;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport jxl.write.*;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport jxl.write.Number;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport jxl.write.Boolean;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifimport java.io.*;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif/** *//**
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * Created by IntelliJ IDEA.
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * User: xl
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * Date: 2005-7-17
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * Time: 9:33:22
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif * To change this template use File | Settings | File Templates.
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifpublic class ExcelHandle
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif    public ExcelHandle()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    /** *//**
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * 读取Excel
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     *
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * @param filePath
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif     */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif    public static void readExcel(String filePath)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        try
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            InputStream is = new FileInputStream(filePath);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Workbook rwb = Workbook.getWorkbook(is);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //Sheet st = rwb.getSheet("0")这里有两种方法获取sheet表,1为名字,而为下标,从0开始
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Sheet st = rwb.getSheet("original");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Cell c00 = st.getCell(0,0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //通用的获取cell值的方式,返回字符串
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            String strc00 = c00.getContents();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //获得cell具体类型值的方式
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            if(c00.getType() == CellType.LABEL)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif            ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                LabelCell labelc00 = (LabelCell)c00;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                strc00 = labelc00.getString();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //输出
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            System.out.println(strc00);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //关闭
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            rwb.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        catch(Exception e)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    /** *//**
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * 输出Excel
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     *
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * @param os
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif     */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif    public static void writeExcel(OutputStream os)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        try
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif            /** *//**
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif             * 只能通过API提供的工厂方法来创建Workbook,而不能使用WritableWorkbook的构造函数,
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif             * 因为类WritableWorkbook的构造函数为protected类型
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif             * method(1)直接从目标文件中读取WritableWorkbook wwb = Workbook.createWorkbook(new File(targetfile));
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif             * method(2)如下实例所示 将WritableWorkbook直接写入到输出流
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif             */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableWorkbook wwb = Workbook.createWorkbook(os);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //创建Excel工作表 指定名称和位置
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableSheet ws = wwb.createSheet("Test Sheet 1",0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //**************往工作表中添加数据*****************
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //1.添加Label对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Label label = new Label(0,0,"this is a label test");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(label);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //添加带有字型Formatting对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableFont wf = new WritableFont(WritableFont.TIMES,18,WritableFont.BOLD,true);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableCellFormat wcf = new WritableCellFormat(wf);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Label labelcf = new Label(1,0,"this is a label test",wcf);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelcf);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //添加带有字体颜色的Formatting对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableFont wfc = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                    UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.RED);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableCellFormat wcfFC = new WritableCellFormat(wfc);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Label labelCF = new Label(1,0,"This is a Label Cell",wcfFC);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelCF);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //2.添加Number对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Number labelN = new Number(0,1,3.1415926);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelN);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //添加带有formatting的Number对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            NumberFormat nf = new NumberFormat("#.##");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableCellFormat wcfN = new WritableCellFormat(nf);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Number labelNF = new jxl.write.Number(1,1,3.1415926,wcfN);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelNF);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //3.添加Boolean对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Boolean labelB = new jxl.write.Boolean(0,2,false);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelB);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //4.添加DateTime对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            jxl.write.DateTime labelDT = new jxl.write.DateTime(0,3,new java.util.Date());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelDT);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //添加带有formatting的DateFormat对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            DateFormat df = new DateFormat("dd MM yyyy hh:mm:ss");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableCellFormat wcfDF = new WritableCellFormat(df);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            DateTime labelDTF = new DateTime(1,3,new java.util.Date(),wcfDF);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addCell(labelDTF);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //添加图片对象,jxl只支持png格式图片
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            File image = new File("f:\2.png");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableImage wimage = new WritableImage(0,1,2,2,image);//0,1分别代表x,y.2,2代表宽和高占的单元格数
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ws.addImage(wimage);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //写入工作表
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            wwb.write();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            wwb.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        catch(Exception e)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    /** *//**
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * 拷贝后,进行修改,其中file1为被copy对象,file2为修改后创建的对象
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * 尽单元格原有的格式化修饰是不能去掉的,我们还是可以将新的单元格修饰加上去,
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * 以使单元格的内容以不同的形式表现
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * @param file1
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif     * @param file2
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif     */
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif    public static void modifyExcel(File file1,File file2)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        try
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            Workbook rwb = Workbook.getWorkbook(file1);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableWorkbook wwb = Workbook.createWorkbook(file2,rwb);//copy
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableSheet ws = wwb.getSheet(0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            WritableCell wc = ws.getWritableCell(0,0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //判断单元格的类型,做出相应的转换
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            if(wc.getType == CellType.LABEL)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif            ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                Label label = (Label)wc;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                label.setString("The value has been modified");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            wwb.write();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            wwb.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            rwb.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        catch(Exception e)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif    //测试
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif    public static void main(String[] args)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        try
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //读Excel
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ExcelHandle.readExcel("f:/testRead.xls");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //输出Excel
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            File fileWrite = new File("f:/testWrite.xls");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            fileWrite.createNewFile();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            OutputStream os = new FileOutputStream(fileWrite);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ExcelHandle.writeExcel(os);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            //修改Excel
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            ExcelHandle.modifyExcel(new file(""),new File(""));
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        catch(Exception e)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif           e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif2.在jsp中做相关测试,创建一个writeExcel.jsp
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif<%
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifresponse.reset();//清除Buffer
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifresponse.setContentType("application/vnd.ms-excel");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifFile fileWrite = new File("f:/testWrite.xls");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.giffileWrite.createNewFile();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifnew FileOutputStream(fileWrite);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifExcelHandle.writeExcel(new FileOutputStream(fileWrite));
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif%>
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif在IE中浏览writeExcel.jsp就可以动态生成Excel文档了,其中response.setContentType ("application/vnd.ms-excel");语句必须要,才能确保不乱码,在jsp中输入<%@page contentType ="application/vnd.ms-excel;charset=GBK"%>不行。 
页: [1]
查看完整版本: JAVA EXCEL API(jxl)简介