I'm exporting a file generated by xlsx.js with my node.js express application server. I'd like to know how to put bold in first line, set auto width and (eventually) colour borders. For example, the first line of the worksheet looks like:
var data = [[
{value:"EXTREMELY LONG TITLE 1", bold: 1, autoWidth:true},
{value:"TITLE2"},
{value:"TITLE3"}
]];
My actual result is that these three cells are correctly printed and served. The attributes bold
and autoWidth
are ignored. How can I get this to work?
I'm exporting a file generated by xlsx.js with my node.js express application server. I'd like to know how to put bold in first line, set auto width and (eventually) colour borders. For example, the first line of the worksheet looks like:
var data = [[
{value:"EXTREMELY LONG TITLE 1", bold: 1, autoWidth:true},
{value:"TITLE2"},
{value:"TITLE3"}
]];
My actual result is that these three cells are correctly printed and served. The attributes bold
and autoWidth
are ignored. How can I get this to work?
- Not sure if there is an order of operations but in his test case it looks like he puts bold before the value. Also try single quotes...I'm just throwing ideas out there I've never used this before. Also sweet name. – Bryce Easley Commented Jan 24, 2014 at 14:44
- @Thunda lol, yours too. Just tried that.. unfortunately without success. Ty anyway – Fra H Commented Jan 24, 2014 at 14:49
2 Answers
Reset to default 2There are a lot of modules that can do it. But if you want to control the formatting of xlsx file, then I suggest you use this below code. Rows contain data in the form of JSON array.
var excel = require('node-excel-export');
var styles = {
headerDark: {
fill: {
fgColor: {
rgb: 'FF000000'
}
},
font: {
color: {
rgb: 'FFFFFFFF'
},
sz: 14,
bold: true,
underline: true
}
},
cellPink: {
fill: {
fgColor: {
rgb: 'FFFFCCFF'
}
}
},
cellGreen: {
fill: {
fgColor: {
rgb: 'FF00FF00'
}
}
}
};
var specification = {
"Col1": {
"displayName": 'Col1Name',
"headerStyle": styles.headerDark,
"width": 250
},
"Col2": {
"displayName": 'Col2Name',
"headerStyle": styles.headerDark,
"width": 215
},
"Col3": {
displayName: 'Col3Name',
headerStyle: styles.headerDark,
width: 150
}
}
var report = excel.buildExport(
[{
name: 'Report.xlsx',
specification: specification,
data: rows
}]
);
This can then be sent either as response in the API :
res.setHeader('Content-disposition', 'attachment; filename=Report.xlsx');
res.send(report);
Or as an attachment in email:
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport({
host: "mail.yourmailman."
}));
transporter.sendMail({
from: "abc.gmail.",
to: toAddr,
subject: 'scheduled reporting',
attachments: [{
'filename': 'Report.xlsx',
'content': new Buffer(report, 'base64')
}]
}, function(error, success) {
if (error) {
logger.error('Error wile sending mail ', error);
return;
} else {
logger.info('Mail sent.. ', success);
return;
}
});
You could use xlsx, js-xlsx or node-xlsx. Create a formatted template and then insert the data into it.
This may help
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744186789a4562241.html
评论列表(0条)