Excel Button Export USPS Tracking Number
Excel Button Export USPS Tracking Number
I am unable to find a reliable solution for exporting USPS Tracking Numbers to Excel. For example, by default, the value "92001902416755000004290987" is exported as "9.2001902416755E+25".
I've tried the following customize option, but it does not work for this data:
customize: function(xlsx) {
//Get the built-in styles
//refer buttons.html5.js "xl/styles.xml" for the XML structure
var styles = xlsx.xl['styles.xml'];
//Create our own style to use the "Text" number format with id: 49
var style = '<xf numFmtId="49" fontId="0" fillId="0" borderId="0" xfId="0" applyFont="1" applyFill="1" applyBorder="1" applyNumberFormat="1"/>';
// Add new node and update counter
el = $('cellXfs', styles);
el.append(style).attr('count', parseInt(el.attr('count'))+1);
// Index of our new style
var styleIdx = $('xf', el).length - 1;
//Apply new style to the first (A) column
var sheet = xlsx.xl.worksheets['sheet1.xml'];
//Set new style default for the column (optional)
$('col:eq(0)', sheet).attr('style', styleIdx);
//Apply new style to the existing rows of the first column ('A')
//Skipping the header row
$('row:gt(0) c[r^="I"]', sheet).attr('s', styleIdx);
}
This one doesn't work either:
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row c[r^="I"]', sheet).attr( 's', '50' );
}
This customizeData option works, but doesn't seem very elegant and I worry about performance with larger datasets:
customizeData: function (data) {
for (var i = 0; i < data.body.length; i++) {
for (var j = 0; j < data.body[i].length; j++) {
if (data.header[j] == "Tracking Numbers") {
data.body[i][j] = '\u200C' + data.body[i][j];
}
}
}
}
Should I just use the customizeData function, or is there another viable solution?
Answers
\u200C
is a cool trick. Seems like the easiest way is to use orthogonal data like this example. I created a quick example to make sure it looks like it works:http://live.datatables.net/tupelexu/1/edit
Kevin
This thread may also be interesting - you've got the crux of it already, but may help.
Cheers,
Colin