生成多个excel文件的程序:(每个outputStream根据webiDocName的不同对应生成不同的excel文件)    for(int i=0;i<文件数;i++)
    {
     ......
      BinaryView docBinaryView =(BinaryView)boReport.getView(OutputFormatType.XLS);    
     byte[] abyBinaryContent = docBinaryView.getContent();    
     outputStream=  new FileOutputStream(path+timePath+random+"\\"+webiDocName+".xls"); 
     outputStream.write(abyBinaryContent);  
    }    现在这个功能要修改成:生成一个excel文件,里面包含多个sheet
怎么做???
我初步是这样写的:    OutputStream  outputStream=new FileOutputStream(path+timePath+random+"\\"+"Reports.xls");
    byte[] abyBinaryContent=null;
    jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(outputStream);
    jxl.write.WritableSheet wsList = wwb.createSheet("目录", 0);
     for(int i=0;i<文件数;i++)
    {
     ......
     BinaryView docBinaryView =(BinaryView)boReport.getView(OutputFormatType.XLS);    
     abyBinaryContent = docBinaryView.getContent();    
     jxl.write.WritableSheet ws = wwb.createSheet(webiDocName, i+1);
    }
    wwb.write();改正后的code结果:生成一个目录,目录里有文件的文件名,是正常的
                   也生成了多个sheet,每个sheet的名称对应的是文件名,也是正常的
                   但是sheet里位空,没有数据

解决方案 »

  1.   

    如果有多个excel合并成一个excel多个sheet的例子也行
    如:http://topic.csdn.net/u/20080708/11/E26402BA-0CC4-43ED-9065-030DBC86BE7C.html
      

  2.   

    往sheet里面加入数据啊。
    WritableSheet wws = wwb.getSheet(0); //获得第一个sheet,可以以此类推
    int k=0; 
    for (int r=2;r <=27;r ) 

    for (int c=4;c <=7;c ) 
    { WritableCellFormat contentFromart = new WritableCellFormat(jxl.write.NumberFormats.TEXT); 
    Label A2=new Label(c,r,sValue[k],contentFromart); 
    WritableFont font= new WritableFont(WritableFont.createFont("宋体"),10,WritableFont.NO_BOLD); 
    WritableCellFormat cellFormat1 = new WritableCellFormat(font); 
    cellFormat1.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); 
    A2.setCellFormat(cellFormat1); 
    wws.addCell(A2); 
    k ; 

    } 本篇文章来源于 www.itzhe.cn IT者网站  原文链接:http://www.itzhe.cn/news/20080219/85654.html
      

  3.   

    直接上代码,LZ拷贝过去运行一下就啥都明白了。
    import java.io.File;
    import java.io.IOException;
    import jxl.Workbook;
    import jxl.format.Colour;
    import jxl.format.UnderlineStyle;
    import jxl.write.Label;
    import jxl.write.WritableCellFormat;
    import jxl.write.WritableFont;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;
    import jxl.write.WriteException;
    import jxl.write.biff.RowsExceededException;public class ExcelUtil1 {    public static void main(String[] args) throws RowsExceededException, WriteException {
            WritableWorkbook wbook;
            try {
                wbook = Workbook.createWorkbook(new File("d:/book.xls"));
        //写入第一页,createSheet后面的0表示位于第一页
                WritableSheet wsheet = wbook.createSheet("第一页", 0);
                WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,
                        WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
                        Colour.PALE_BLUE);
                WritableCellFormat wcfFC = new WritableCellFormat(wfont);
                for (int i = 0; i < 10; i++) {
                    wsheet.addCell(new Label(0, i, "第一页" + i + ""));
                    wsheet.addCell(new Label(1, i, "第一页" + i + ""));
                    wsheet.addCell(new Label(2, i, "第一页" + i + ""));
                    wsheet.addCell(new Label(3, i, "第一页" + i + ""));
                    wsheet.addCell(new Label(4, i, "第一页" + i + ""));
                    wsheet.addCell(new Label(5, i, "第一页" + i + ""));
                }
                //写入第二页
                wsheet = wbook.createSheet("第二页", 1);
                for (int i = 0; i < 10; i++) {
                    wsheet.addCell(new Label(0, i, "第二页" + i + ""));
                    wsheet.addCell(new Label(1, i, "第二页" + i + ""));
                    wsheet.addCell(new Label(2, i, "第二页" + i + ""));
                    wsheet.addCell(new Label(3, i, "第二页" + i + ""));
                    wsheet.addCell(new Label(4, i, "第二页" + i + ""));
                    wsheet.addCell(new Label(5, i, "第二页" + i + ""));
                }
                wbook.write(); // 写入文件
                wbook.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }