//自己写的适用于handsontable插件的表格导出方法,用到了插件的配置信息,请将表格对象设为全局对象
var saveData = function(data,filename,type){
saveAs(new Blob([data], {type: 'application/vnd.ms-excel'}), filename + "."+type);
};
//对时间Date对象进行格式化重写
Date.prototype.Format = function(fmt) { // author: meizz
var o = {
"M+" : this.getMonth() + 1, // 月份
"d+" : this.getDate(), // 日
"h+" : this.getHours(), // 小时
"m+" : this.getMinutes(), // 分
"s+" : this.getSeconds(), // 秒
"q+" : Math.floor((this.getMonth() + 3) / 3), // 季度
"S" : this.getMilliseconds()
// 毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
for ( var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
: (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
function DataToExcel(data,filename,type) {//导出handsontable插件的excel表格
var tmpl = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+type+"' xmlns='http://www.w3.org/TR/REC-html40'>";
tmpl += "<head><meta charset='UTF-8' /><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>";
tmpl += filename+"</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->";
tmpl += "</head><body><table>";
//console.log(data)
var tableTitle=[];
//设置表头
var tableTitleTr=[];
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>项目编号</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>项目名称</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>采购人</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>采购联系人</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>编制人</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>接收人</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>中标供应商</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>供应商联系人</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>采购方式</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>预算(元)</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>成交金额(元)</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>评审日期</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;text-align:center;font-weight:bold;'>是否流标</td>");
tableTitle.push(tableTitleTr);
//设置数据
for(var i=0;i<data.length;i++){
var tableTitleTr=[];
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].tenderItemNo+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].tenderItemName+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].buyerName+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].buyerContact+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].prepareManName+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].receiverManName+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].providerName+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].offerer+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].bidMethodName+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].buyertotalBudget+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+data[i].lastBidPrice+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+new Date(data[i].evalutionEndtime).Format("yyyy-MM-dd ")+"</td>");
tableTitleTr.push("<td style='border:1px solid #ccc;mso-number-format:\"\@\"'>"+flagFormatter()+"</td>");
tableTitle.push(tableTitleTr);
}
for(var index=0;index< tableTitle.length;index++){
tmpl+="<tr>"+tableTitle[index].join("")+"</tr>";
}
tmpl+="</table></body></html>