|
|
@ -31,6 +31,7 @@ import com.bstek.ureport.console.cache.TempObjectCache; |
|
|
|
import com.bstek.ureport.console.exception.ReportDesignException; |
|
|
|
import com.bstek.ureport.definition.ReportDefinition; |
|
|
|
import com.bstek.ureport.exception.ReportComputeException; |
|
|
|
import com.bstek.ureport.exception.ReportException; |
|
|
|
import com.bstek.ureport.export.ExportConfigure; |
|
|
|
import com.bstek.ureport.export.ExportConfigureImpl; |
|
|
|
import com.bstek.ureport.export.ExportManager; |
|
|
@ -69,38 +70,43 @@ public class ExportExcelServletAction extends BaseServletAction { |
|
|
|
if(StringUtils.isBlank(file)){ |
|
|
|
throw new ReportComputeException("Report file can not be null."); |
|
|
|
} |
|
|
|
String fileName=req.getParameter("_n"); |
|
|
|
fileName=buildDownloadFileName(file, fileName, ".xlsx"); |
|
|
|
resp.setContentType("application/octet-stream;charset=ISO8859-1"); |
|
|
|
fileName=new String(fileName.getBytes("UTF-8"),"ISO8859-1"); |
|
|
|
resp.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\""); |
|
|
|
Map<String, Object> parameters = buildParameters(req); |
|
|
|
OutputStream outputStream=resp.getOutputStream(); |
|
|
|
if(file.equals(PREVIEW_KEY)){ |
|
|
|
ReportDefinition reportDefinition=(ReportDefinition)TempObjectCache.getObject(PREVIEW_KEY); |
|
|
|
if(reportDefinition==null){ |
|
|
|
throw new ReportDesignException("Report data has expired,can not do export excel."); |
|
|
|
} |
|
|
|
Report report=reportBuilder.buildReport(reportDefinition, parameters); |
|
|
|
if(withPage){ |
|
|
|
excelProducer.produceWithPaging(report, outputStream); |
|
|
|
}else if(withSheet){ |
|
|
|
excelProducer.produceWithSheet(report, outputStream); |
|
|
|
}else{ |
|
|
|
excelProducer.produce(report, outputStream); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
ExportConfigure configure=new ExportConfigureImpl(file,parameters,outputStream); |
|
|
|
if(withPage){ |
|
|
|
exportManager.exportExcelWithPaging(configure); |
|
|
|
}else if(withSheet){ |
|
|
|
exportManager.exportExcelWithPagingSheet(configure); |
|
|
|
try { |
|
|
|
String fileName=req.getParameter("_n"); |
|
|
|
fileName=buildDownloadFileName(file, fileName, ".xlsx"); |
|
|
|
resp.setContentType("application/octet-stream;charset=ISO8859-1"); |
|
|
|
fileName=new String(fileName.getBytes("UTF-8"),"ISO8859-1"); |
|
|
|
resp.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\""); |
|
|
|
Map<String, Object> parameters = buildParameters(req); |
|
|
|
if(file.equals(PREVIEW_KEY)){ |
|
|
|
ReportDefinition reportDefinition=(ReportDefinition)TempObjectCache.getObject(PREVIEW_KEY); |
|
|
|
if(reportDefinition==null){ |
|
|
|
throw new ReportDesignException("Report data has expired,can not do export excel."); |
|
|
|
} |
|
|
|
Report report=reportBuilder.buildReport(reportDefinition, parameters); |
|
|
|
if(withPage){ |
|
|
|
excelProducer.produceWithPaging(report, outputStream); |
|
|
|
}else if(withSheet){ |
|
|
|
excelProducer.produceWithSheet(report, outputStream); |
|
|
|
}else{ |
|
|
|
excelProducer.produce(report, outputStream); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
exportManager.exportExcel(configure); |
|
|
|
ExportConfigure configure=new ExportConfigureImpl(file,parameters,outputStream); |
|
|
|
if(withPage){ |
|
|
|
exportManager.exportExcelWithPaging(configure); |
|
|
|
}else if(withSheet){ |
|
|
|
exportManager.exportExcelWithPagingSheet(configure); |
|
|
|
}else{ |
|
|
|
exportManager.exportExcel(configure); |
|
|
|
} |
|
|
|
} |
|
|
|
}catch(Exception ex) { |
|
|
|
throw new ReportException(ex); |
|
|
|
}finally { |
|
|
|
outputStream.flush(); |
|
|
|
outputStream.close(); |
|
|
|
} |
|
|
|
outputStream.flush(); |
|
|
|
outputStream.close(); |
|
|
|
} |
|
|
|
|
|
|
|
public void setReportBuilder(ReportBuilder reportBuilder) { |
|
|
|