jeesite導入導出


$("#btnImport").click(function() {
$.jBox($("#importBox").html(), {title:"導入數據", buttons:{"關閉":true},
bottomText:"導入文件不能超過5M,僅允許導入“xls”或“xlsx”格式文件!"});
});
$("#btnExport").click(function(){
var index=document.getElementById('remark5').selectedIndex;
var zhi=document.getElementById('remark5').options[index].text;
$("#remark6").val(zhi);
top.layer.confirm('確認要導出Excel嗎?', {icon: 3, title:'系統提示'}, function(index){
//do something
//導出之前備份
var url = $("#searchForm").attr("action");
var pageNo = $("#pageNo").val();
var pageSize = $("#pageSize").val();
//導出excel
$("#searchForm").attr("action","${ctx}/hp/hpCloth/export");
/* $("#pageNo").val(-1);
$("#pageSize").val(-1);*/
$("#searchForm").submit();

//導出excel之后還原
$("#searchForm").attr("action",url);
$("#pageNo").val(pageNo);
$("#pageSize").val(pageSize);
top.layer.close(index);
});
});
<div id="importBox" class="hide">
<form id="importForm" action="${ctx}/hp/hpCloth/import" method="post" enctype="multipart/form-data"
class="form-search" style="padding-left:20px;text-align:center;" onsubmit="loading('正在導入,請稍等...');"><br/>
<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>  
<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="確認導入"/>
<a href="${ctx}/hp/hpCloth/exportTemp" class="btn btn-primary">下載模板</a>
</form>
</div>
<li class="btns">
<button id="btnImport" type="button" class="btn btn-primary " data-toggle="tooltip" data-placement="left" title="導入">
<i class="fa fa-file-excel-o"></i> 導入</button>
</li>
<li class="btns">
<button id="btnExport" type="button" class="btn btn-primary " data-toggle="tooltip" data-placement="left" title="導出">
<i class="fa fa-file-excel-o"></i> 導出</button>
</li>


//Excel導入數據
@RequestMapping(value = "import")
public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel imEx = new ImportExcel(file, 1, 0);
List<HpCloth> wlCatalogList = imEx.getDataList(HpCloth.class);
for (HpCloth wlCatalog : wlCatalogList) {
try {
hpClothService.save(wlCatalog);
successNum++;
} catch (ConstraintViolationException ex) {
failureMsg.append("<br/>物料名稱 " + wlCatalog.getBrand() + " 導入失敗:");
List<String> messageList = BeanValidators.extractPropertyAndMessageAsList(ex, ": ");
for (String message : messageList) {
failureMsg.append(message + "; ");
failureNum++;
}
} catch (Exception ex) {
failureMsg.append("<br/>物料名稱 " + wlCatalog.getBrand() + " 導入失敗:" + ex.getMessage());
}
}
if (failureNum > 0) {
failureMsg.insert(0, ",失敗 " + failureNum + " 條數據,導入信息如下:");
}
addMessage(redirectAttributes, "已成功導入 " + successNum + " 條數據" + failureMsg);
} catch (Exception e) {
addMessage(redirectAttributes, "導入物料數據失敗!失敗信息:" + e.getMessage());
}
return "redirect:" + Global.getAdminPath() + "/wl/wlCatalog/list?repage";
}

@RequestMapping(value = "export")
public String exportFile(HpCloth hpCloth, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "當前庫存數據"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<HpCloth> page = hpClothService.findPage(new Page<HpCloth>(request, response), hpCloth);
new ExportExcel("當前庫存數據", HpCloth.class).setDataList(page.getList()).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "導出當前庫存數據失敗!失敗信息:"+e.getMessage());
}
return "redirect:" + adminPath + "/hp/hpCloth/list?repage";
}



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM