Front/JS & jQuery

[datatables] excel export style 만들기

오선지♬ 2023. 10. 11. 18:37
728x90
반응형

https://datatables.net/forums/discussion/comment/206900/#Comment_206900

 

Excel Export

I think Excel is still important in so many ways. Over 50% of my users want to be able to easily export their data to Excel.

datatables.net

 

var sSh = xlsx.xl['styles.xml'];
var lastXfIndex = $('cellXfs xf', sSh).length - 1;

var s1 = '<xf numFmtId="300" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>';
//define the style with the new font (number passed in as a variable)
var s2 = '<xf numFmtId="0" fontId="'+(lastFontIndex+1)+'" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">'+
            '<alignment horizontal="center"/></xf>';        
var s3 = '<xf numFmtId="0" fontId="2" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">'+
            '<alignment horizontal="center" wrapText="1"/></xf>'
            
sSh.childNodes[0].childNodes[5].innerHTML += s1 + s2 + s3; //new styles

var fourDecPlaces    = lastXfIndex + 1;
var greyBoldCentered = lastXfIndex + 2;
var greyBoldWrapText = lastXfIndex + 3;
 
 
$('row:eq(0) c', sheet).attr( 's', greyBoldCentered );  //grey background bold and centered, as added above
$('row:eq(1) c', sheet).attr( 's', greyBoldWrapText );  //grey background bold, text wrapped
728x90
반응형

'Front > JS & jQuery' 카테고리의 다른 글

[datatables] createdCell로 tr에 Class 적용하기  (0) 2023.10.23
[echarts]chart click event 적용하기  (0) 2023.10.12
[datatables] excel export style  (1) 2023.10.10
[js] spread syntax  (0) 2023.10.09
[js] Math.min() / Math.max()  (0) 2023.10.08