How to apply style on data rows but not header in Excel

How to apply style on data rows but not header in Excel

databodydatabody Posts: 11Questions: 3Answers: 0

So I want to apply some style like wrap text and I am using following code but it also applies style on header row which I don't want. I only want style to be applied on data rows. How to make it possible?

customize: function( xlsx ) {
                    var sheet = xlsx.xl.worksheets['sheet1.xml'];

                    $('row c[r^="D"]', sheet).attr( 's', '55' );
                    $('row c[r^="F"]', sheet).attr( 's', '55' );

                }

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    Answer ✓

    This thread may give you some hints on how to achieve this:
    https://datatables.net/forums/discussion/comment/167672/#Comment_167672

    This could already bring you pretty close to a solution. If your header is two cols high start with i=2 etc.

    customize: function( xlsx ) {
        var sheet = xlsx.xl.worksheets['sheet1.xml'];
        var rows = $('row', sheet);    
        for ( var i=1; i < rows.lenght; i++ ) {
            $('row:eq('+i+') c[r^="D"]', sheet).attr( 's', '55' );
            $('row:eq('+i+') c[r^="F"]', sheet).attr( 's', '55' );
         }
    }
    
  • databodydatabody Posts: 11Questions: 3Answers: 0

    Thanks it worked. But there is slight problem with above code i.e. you have written rows.lenght and instead it should be rows.length

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Right! I typed much of the code directly into the form ... then you get typos, sorry :smile:

    One thing to know: You can't apply multiple built-in styles to the same cell or row. Because the styles overwrite each other. That is when the trouble starts: You have to define your own styles and that is cumbersome. You'll find much on this in the forum in case you need it.

Sign In or Register to comment.