用户有一个需求,需要将数据按一定规则,拆分成多个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个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不知道怎么实现,请教各位是否有解?
--------------------------------
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();
}
}}
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)
用zip包试试吧。也许是我误导了,不好意思。
这种方式怎么做