项目中用到的导出数据到Excel记录下
需要包:poi-3.9.jar
页面代码:
/**
* 显示所有列,勾选需要导出的
*
*/
function exportModel(tableId){
var tableParams = getLocalStorageModel(tableId, "tableParams");
var totalHtml ='<div class="modal fade modal-primary" id="'+tableId +'-edit" aria-hidden="true"><div class="modal-dialog" style="width: 200px;"><div class="modal-content">';
totalHtml+='<div class="modal-header"><button type="button" class="close" οnclick="removeModal(\''+tableId+'\',\'edit\')">';
totalHtml+='<span aria-hidden="true">×</span></button><h4 class="modal-title text-success" ng-class="text-success" id="'+tableId+'-edit-header"><i class="fa fa-plus"></i>'+$.i18n("exportData")+'</h4></div><div class="ng-scope" style="padding-top:15px;height: 290px;overflow-y: auto;">';
totalHtml+='<li style="border-bottom: 1px solid #00A2E9;height:30px;"><div class="pull-left"><label style="margin: 0 0 0 20px;"><input type="checkbox" id="'+tableId+'-export-checkAllBtn" οnchange="checkAllShowExportItems(\''+tableId+'\')"><span class="text"></span></label>'+$.i18n("check_all")+'</div></li>';
totalHtml+='<div id="'+tableId+'-export-RowPopId"></div>';
totalHtml+='</div><div class="modal-footer " style="background-color:#FFFFFF;"><button type="button" class="btn btn-primary" οnclick="sbmtExport(\''+tableId+'\')">'+$.i18n("exportData");
totalHtml+='</button><a class="btn btn-danger" οnclick="removeModal(\''+tableId+'\',\'edit\')">'+$.i18n("cancel")+'</a></div></div></div></div>';
$("body").append(totalHtml);
exportRowsModel(tableId,tableParams);
var $editModal = $('#'+tableId + "-edit");
$editModal.modal({
backdrop: 'static'});
setTimeout(function () {
$editModal.find("span.error").remove();
$editModal.find("input.error").removeClass("error");
}, 200);
}
function exportRowsModel(tableId, tableItems){
var selectRowsPopId = tableId + "-export-RowPopId";//显示列下拉框ID
var allCheckBtnId = tableId + "-export-checkAllBtn";//全选框ID
var i18nPrefix = getLocalStorageModel(tableId, "tableParams").i18nPrefix;
var html = "";
var selectItemsjson = tableItems.trs;
var len = selectItemsjson.length;
for(var i=0; i<len; i++){
if(selectItemsjson[i].lastShow === false || selectItemsjson[i].comType == "uploadFiles"){
continue;
}
html+= "<li οnclick='event.stopPropagation()'><label style='margin: 0 0 0 20px;'>";
html+= "<input type='checkbox'";
if(!(selectItemsjson[i].show === false)){
html+= " checked ";
}
var name = selectItemsjson[i].name;
var title = $.i18n(i18nPrefix + name)||$.i18n("db.common." + name);
html+= "name='"+selectRowsPopId+"' value='"+name+"' οnchange='changeShowExportItems(\""+tableId+"\")'>";
html+= "<span class='text'></span></label>"+title +"</li>";
}
$("#"+selectRowsPopId).html(html);
//是否勾选全选框
var chsub = $("input[name='"+selectRowsPopId+"']").length; //获取items的个数
var checkedsub = $("input[name='"+selectRowsPopId+"']:checked").length; //获取选中的items的个数
$("#"+allCheckBtnId).attr("checked", checkedsub == chsub);
}
function changeShowExportItems(tableId){
var selectRowsPopId = tableId + "-export-RowPopId";//显示列下拉框ID
var itemsLen = $("input[name='"+selectRowsPopId+"']").length; //获取items的个数
var checkedItemsLen = $(