Hi I want to download the excel file by clicking the Export button.
I am using this reference link to create the excel file https://www.npmjs.com/package/excel4node
Html page
<button ng-click="exportData()" class="btn btn-sm btn-primary btn-create">Export</button>
Controller.js
$scope.exportData = function () {
$http.get('/Getexcel').then(function (response) {
});
};
Server.js
var xl = require('excel4node');
const tempfile = require('tempfile');
// Create a new instance of a Workbook class
var wb = new xl.Workbook();
// Add Worksheets to the workbook
var ws = wb.addWorksheet('MaterialFlowSheet');
// Create a reusable style
var style = wb.createStyle({
font: {
color: '#FF0800',
size: 12
},
numberFormat: '$#,##0.00; ($#,##0.00); -'
});
app.get('/Getexcel', function (req, res) {
ws.cell(1, 1).string('BatchId').style(style);
ws.cell(1, 2).string('Source').style(style);
ws.column(2).setWidth(50);
ws.row(1).setHeight(20);
ws.cell(1, 3).string('Destination').style(style);
ws.column(3).setWidth(50);
ws.row(1).setHeight(20);
ws.cell(1, 4).string('DistanceBetweenTwoBuilding').style(style);
ws.column(4).setWidth(25);
ws.row(1).setHeight(20);
ws.cell(1, 5).string('SKU').style(style);
ws.cell(1, 6).string('UOM').style(style);
ws.cell(1, 7).string('QtyToBeDelivered').style(style);
ws.column(7).setWidth(20);
ws.row(1).setHeight(20);
ws.cell(1, 8).string('CartType').style(style);
ws.addDataValidation({
type: 'list',
allowBlank: true,
showDropDown: true,
sqref: 'b2:b1000',
formulas: [
'asdf,fh,dfhj'
]
});
wb.write('Excel.xlsx',req);
res.download('Excel.xlsx');
});
I am did n't get any error. excel file is also not downloading can anyone tell me am doing correct or am i made any mistake in my code.
Thanks,
via Vinoth
No comments:
Post a Comment