jxls根據模板匯出excel
public class ExportExcel{
HttpServletRequest request;
HttpServletResponse response;
List saff;
String fileName;
public ExportExcel(HttpServletRequest request, HttpServletResponse response, List saff, String fileName ){
this.request=request;
this.response=response;
this.saff=saff;
this.fileName=fileName;
}
public void exportProject(String sourceName)throws Exception{
Map<String,Object> map=new HashMap<>();
map.put("fileName",fileName);
map.put("testforms",saff);
//獲得模板路徑
String path=request.getServletContext().getRealPath("excel_export");
String wjpath=path+ File.separator+sourceName;
//準備輸出流
OutputStream os=null;
try {
//設定響應頭
response.setContentType("application/x-excel");
//response.setHeader("Content-Disposition", "attachment;filename=studentInfo.xls");
response.setHeader("Content-Disposition", "attachment;filename="+new String((fileName+".xls").getBytes(),"iso8859-1"));
response.setContentType("application/ms-excel");
os = response.getOutputStream();
XLSTransformer transformer = new XLSTransformer();
try {
//獲得模板的輸入流
InputStream in = new BufferedInputStream(new FileInputStream(wjpath));
//將beans通過模板輸入流寫到workbook中
Workbook workbook = transformer.transformXLS(in, map);
//將workbook中的內容用輸出流寫出去
workbook.write(os);
os.flush();
}catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
} catch (Exception e) {
e.printStackTrace();
}
}
HttpServletRequest request;
HttpServletResponse response;
List saff;
String fileName;
public ExportExcel(HttpServletRequest request, HttpServletResponse response, List saff, String fileName ){
this.request=request;
this.response=response;
this.saff=saff;
this.fileName=fileName;
}
public void exportProject(String sourceName)throws Exception{
Map<String,Object> map=new HashMap<>();
map.put("fileName",fileName);
map.put("testforms",saff);
//獲得模板路徑
String path=request.getServletContext().getRealPath("excel_export");
String wjpath=path+ File.separator+sourceName;
//準備輸出流
OutputStream os=null;
try {
//設定響應頭
response.setContentType("application/x-excel");
//response.setHeader("Content-Disposition", "attachment;filename=studentInfo.xls");
response.setHeader("Content-Disposition", "attachment;filename="+new String((fileName+".xls").getBytes(),"iso8859-1"));
response.setContentType("application/ms-excel");
os = response.getOutputStream();
XLSTransformer transformer = new XLSTransformer();
try {
//獲得模板的輸入流
InputStream in = new BufferedInputStream(new FileInputStream(wjpath));
//將beans通過模板輸入流寫到workbook中
Workbook workbook = transformer.transformXLS(in, map);
//將workbook中的內容用輸出流寫出去
workbook.write(os);
os.flush();
}catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
demo下載地址 http://download.csdn.net/download/maple980326/9959219
相關部落格地址: http://blog.csdn.net/yuliqi0429/article/details/41907711
相關文章
- apose 根據excel 匯出模版Excel
- java匯出Excel定義匯出模板JavaExcel
- Excel模板匯出之動態匯出Excel
- 模板匯出word和 EXcelExcel
- Java 根據模板生成 PDF 檔案 以及 excel 檔案JavaExcel
- MysqlDump根據萬用字元批量匯出MySql字元
- activiti 根據模型ID匯出、預覽 xml檔案模型XML
- SpringBoot圖文教程10—Excel模板匯出|百萬資料匯出|圖片匯出「easypoi」Spring BootExcel
- 如何根據exp匯出檔案確定client端匯出時的字符集client
- 匯出excelExcel
- 根據介面返回的二進位制流匯出檔案
- vue excel匯入匯出VueExcel
- js匯出EXCELjs匯出EXCELJSExcel
- excel根據某一列匹配資料Excel
- PHP 匯出 ExcelPHPExcel
- PHP匯出EXCELPHPExcel
- Vue匯出ExcelVueExcel
- Java匯出ExcelJavaExcel
- php 匯出excelPHPExcel
- POI 匯出ExcelExcel
- spring boot itextPdf根據模板生成pdf檔案Spring Boot
- Angular Excel 匯入與匯出AngularExcel
- freemarker根據靜態模板和動態模板生成PDF與Word
- 騰訊文件怎樣匯出excel表格 騰訊文件如何匯出excelExcel
- Java 通過Xml匯出Excel檔案,Java Excel 匯出工具類,Java匯出Excel工具類JavaXMLExcel
- js匯出Excel表格JSExcel
- vue匯出Excel表格VueExcel
- Excel優雅匯出Excel
- Excel匯出實列Excel
- Springmvc匯出excelSpringMVCExcel
- appfuse:Excel匯出APPExcel
- DataGridView匯出ExcelViewExcel
- vue 前端匯出 excelVue前端Excel
- poi的excel匯出Excel
- kxcel, 方便匯入和匯出 ExcelExcel
- vue + element + 匯入、匯出excel表格VueExcel
- 轉java操作excel匯入匯出JavaExcel
- Vue框架下實現匯入匯出Excel、匯出PDFVue框架Excel