/***
* 給出 模板和資料 自動生成excel
* * @param type 預設為0
* @param path 模版路徑
* @param title 要顯示的標題--未用到
* @param exportname 匯出名稱
* @param tablehead 列表的表頭 --未用到
* @param datalist 資料項
* @param datatypelist 資料項對應的資料型別
* @param mapcount
* @param insertheadinfo 插入到表頭的資料
// 迴圈資料
for (int i = 0; i < datalist.size(); i++) else if (datatypelist[j].equals("int")) else }}
sheet.getrow(0).getcell(0).setcellvalue(maintitle);//設定表頭
sheet.getrow(1).getcell(2).setcellvalue(projectname);
sheet.getrow(1).getcell(7).setcellvalue(producttype);
response.reset();
response.setheader(
"content-disposition",
"attachment; filename="
+ urlencoder.encode(
exportname
+ (exportname.endswith(".xls") ? ""
: ".xls"), "utf-8"));
servletoutputstream output = response.getoutputstream();
workbook.write(output);
output.flush();
output.close();
} catch (filenotfoundexception e) catch (ioexception e)
}
獲取資料
string path= request.getrealpath("excel/出庫資訊.xls");
path=path.replace('\\', '/');
mapinsertheadinfo = new hashmap();//插入到表頭的資料
insertheadinfo.put("maintitle",maintitle );
insertheadinfo.put("producttype", producttype);
insertheadinfo.put("projectname", projectname);
string datatypelist = ;
return new modelandview (new excelexport(0, path, "", exportname, tablehead, datalist, datatypelist, null,insertheadinfo, response));
Java匯出excel(無模板匯出excel)
匯出標題 string metadata 匯出資料 list datalist data data 為需要匯出的資料 生成資料列 listdata new arraylist 生成列資料 for mapdatatemp datalist 匯出資料名稱 string filename excel名稱 ...
通過Excel模板進行POI匯出excel資料
需要滿足匯出的excel資料能夠匯入到專案中,目前通過poi對excel模板進行讀取,然後在進行寫入資料,最後實現匯出功能。啥也不說 上 轉殖模板中的workbook 主方法 填充資料 可以 裝入map中 獲取資料 資料1 office office userutils.getcurrentorga...
根據excel模版匯出資料到excel
匯出模版的位置 if temppath.length 0 else public class excelhelper 利用模板,datatable匯出到excel 單個類別 datatable 模板的檔案路徑 名稱 檔案標識 sheet名 1 經營 情況 2 生產經營情況 3 專案投資情況 4 房產...