用户有一个需求,需要将数据按一定规则,拆分成多个excel导出。
一次导出1个excel是没有问题。我的实现方式是:
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-disposition","attachment;filename=" + fileName);
String strExcel = "";//excel内容
PrintWriter outW= response.getWriter();
outW.write(strExcel);
outW.flush();
outW.close();多个excel不知道怎么实现,请教各位是否有解?

解决方案 »

  1.   

    或者导出zip包,里面是多个excel。
      

  2.   

    只能导出个xsl压缩包给客户端了
      

  3.   

    多线程好像不可以哦。有问题。不知道我的写法是否有问题。
    --------------------------------
    new ExportExcelThread(response,requestPath).start()public class ExportExcelThread extends Thread {
    HttpServletResponse response;
    String requestPath;    public ExportExcelThread(HttpServletResponse response,String requestPath) {
            this.response = response;
            this.requestPath = requestPath;
        }    public void run() {
            try {
                     OutputStream out = response.getOutputStream();
    FileInputStream fis = new FileInputStream(requestPath);
    int data = 0;
    while((data = fis.read()) != -1){
    out.write(data);
    }
    out.flush();
    fis.close();
    out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }}
      

  4.   

    总是报错:16:19:23,984 ERROR [STDERR]     at java.lang.System.arraycopy(Native Method)
    16:19:23,984 ERROR [STDERR]     at org.apache.tomcat.util.buf.ByteChunk.append(B
    yteChunk.java:346)
    16:19:23,984 ERROR [STDERR]     at org.apache.coyote.http11.InternalOutputBuffer
    $OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:761)
    16:19:23,984 ERROR [STDERR]     at org.apache.coyote.http11.filters.ChunkedOutpu
    tFilter.doWrite(ChunkedOutputFilter.java:129)
    16:19:23,984 ERROR [STDERR]     at org.apache.coyote.http11.InternalOutputBuffer
    .doWrite(InternalOutputBuffer.java:570)
    16:19:23,984 ERROR [STDERR]     at org.apache.coyote.Response.doWrite(Response.j
    ava:560)
    16:19:23,984 ERROR [STDERR]     at org.apache.catalina.connector.OutputBuffer.re
    alWriteBytes(OutputBuffer.java:353)
    16:19:23,984 ERROR [STDERR]     at org.apache.tomcat.util.buf.ByteChunk.flushBuf
    fer(ByteChunk.java:434)
    16:19:23,984 ERROR [STDERR]     at org.apache.tomcat.util.buf.ByteChunk.append(B
    yteChunk.java:293)
    16:19:23,984 ERROR [STDERR]     at org.apache.catalina.connector.OutputBuffer.wr
    iteByte(OutputBuffer.java:399)
    16:19:23,984 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteOutputStr
    eam.write(CoyoteOutputStream.java:77)
      

  5.   

    恩,server的多线程只是内部的,同时生成多个excel,但是下发肯定是串行啊。
    用zip包试试吧。也许是我误导了,不好意思。
      

  6.   

    非常感谢各位,已解决。先生成多个excel,再打包成zip.客户端下载保存zip文件即可。
      

  7.   

    先生成多个excel,再打包成zip.客户端下载保存zip文件即可
    这种方式怎么做