Excel export with background

Excel export with background

tianchaotianchao Posts: 7Questions: 4Answers: 0

1,隔行变色:

$(document).ready(function() {

 $('#example').DataTable({

  dom: 'Bfrtip',

  buttons: [{

   extend: 'excelHtml5',

   customize: function ( xlsx ) {

    var sheet = xlsx.xl.worksheets['sheet1.xml'];

    $('row', sheet).each(function(x) {

     if(x %2 == 0){

      if ($('c[r=A'+x+'] t', sheet)) {

       $('row:nth-child('+x+') c', sheet).attr('s', '30');

      }

     }

   });

   }

  }]

 });

});

2,某一个单元格包含特定字符串

$(document).ready(function() {
 $('#example').DataTable({

  dom: 'Bfrtip',

  buttons: [{

   extend: 'excelHtml5',

   customize: function ( xlsx ) {

    var sheet = xlsx.xl.worksheets['sheet1.xml'];
    $('row', sheet).each(function(x) {

     if ($('c[r=C'+x+'] t', sheet).text().indexOf('Edin') !=-1) {

      $('row:nth-child('+x+') c', sheet).attr('s', '10');

     }

   });

   }

  }]

 });

});

3,特定行变色

$(document).ready(function() {



 $('#example').DataTable({

  dom: 'Bfrtip',

  buttons: [{

   extend: 'excelHtml5',

   customize: function ( xlsx ) {

    var sheet = xlsx.xl.worksheets['sheet1.xml'];

 



    $('row', sheet).each(function(x) {

     if (x ==1 || x==2 || x==3) {

      $('row:nth-child('+x+') c', sheet).attr('s', '10');

     }

     else if(x ==7 || x==8 || x==9){

      $('row:nth-child('+x+') c', sheet).attr('s', '39');

     }

   });

   }

  }]

 });

});

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Does this relate to your other thread? And does my reply there resolve your issue?

    Colin

  • tianchaotianchao Posts: 7Questions: 4Answers: 0

    this is my answer, I solved this problem,thx Colin

Sign In or Register to comment.