app.get('/api/contracts/exportExcel/:id',contract.exportExcel);//跳轉(zhuǎn)到后臺(tái)
exports.exportExcel = function(req, res) {
/**靜態(tài)數(shù)據(jù)
* var conf ={};
conf.cols = [ {caption:'string', type:'string'}, {caption:'date', type:'date'}, {caption:'bool', type:'bool'}, {caption:'number', type:'number'} ]; conf.rows = [ ['pi', (new Date(2013, 4, 1)).getJulian(), true, 3.14], ["e", (new Date(2012, 4, 1)).getJulian(), false, 2.7182] ]; var result = nodeExcel.execute(conf); res.setHeader('Content-Type', 'application/vnd.openxmlformats'); res.setHeader("Content-Disposition", "attachment; filename=" + "Report.xlsx"); res.end(result, 'binary');
**/
console.log("req.params.id:"+req.params.id);
var queryId = req.params['id']+'';
var contract = new Contract();
var conf = {};
conf.cols = [
{caption:'采購(gòu)編號(hào)', type:'string'},
{caption:'合同名稱(chēng)', type:'string'},
{caption:'甲方', type:'string'},
{caption:'甲方部門(mén)', type:'string'},
{caption:'乙方', type:'string'},
{caption:'乙方部門(mén)', type:'string'},
{caption:'簽訂日期', type:'date'},
{caption:'中標(biāo)日期', type:'date'},
{caption:'結(jié)束日期', type:'date'},
{caption:'銷(xiāo)售負(fù)責(zé)人', type:'string'},
{caption:'商務(wù)負(fù)責(zé)人', type:'string'},
{caption:'業(yè)績(jī)歸屬部門(mén)', type:'string'},
{caption:'金額', type:'number'},
{caption:'狀態(tài)', type:'string'}
];
var getId = {
_id: queryId
};
contract.checkIdData(getId,function(data){
console.log("lijuanxia");
console.log("data.lentht"+data.length);
var m_data = [];
var arry = [data[0].myId, data[0].name, data[0].partyA, data[0].partyADept, data[0].partyB, data[0].partyBDept, data[0].signDate, data[0].beginDate, data[0].endDate, "銷(xiāo)售負(fù)責(zé)人", "商務(wù)負(fù)責(zé)人", "業(yè)績(jī)歸屬部門(mén)", data[0].amount, data[0].state ];
m_data[0] = arry;
conf.rows = m_data;
var result = nodeExcel.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader("Content-Disposition", "attachment; filename=" +data[0].name+ ".xlsx");
res.end(result, 'binary');
});
}