freeze header row in generated Excel

freeze header row in generated Excel

gloftusgloftus Posts: 2Questions: 1Answers: 0
edited August 2021 in Buttons

Hello ~ I am trying to freeze the header row in an Excel file that is being created from a data table. The buttons are defined as follows. I'm looking for the equivalent of FreezePanes() or SplitRow(). Thank you!

buttons: [
            {
                extend: 'excelHtml5',
                text: '<i class="fa fa-file-excel-o"></i>',
                className: 'btn-excel',
                titleAttr: 'Excel',
                filename: 'xxx',
                title: function () {if (cboxXXXchecked === true) return 'Active';
                                else { return 'All'; }
                        },  selection.
                customize: function (xlsx) {
                    var sheet = xlsx.xl.worksheets['sheet1.xml'];
                    $('row:eq(0) c', sheet).attr('s', '50');  //50=left aligned
                    $('row:eq(0) c', sheet).attr('s', '2');  //2=bold
                    $('row:eq(1) c', sheet).attr('s', '7');  //7=grey background


                },
                autoFilter: true,
                exportOptions: { columns: [0,1,2,3,4,5,6,7,8,9,10,11] }  
            }
        ],

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

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

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • gloftusgloftus Posts: 2Questions: 1Answers: 0
    edited August 2021

    Thank you! That was exactly what I needed. It took a bit to figure how to change it from freezing the first 3 columns to freezing the top two rows, so I'm posting what worked for me in case it helps the next person...

    customize: function (xlsx) {
    var sheet = xlsx.xl.worksheets['sheet1.xml'];
    
    var f1 = `<sheetViews>
         <sheetView tabSelected="1" workbookViewId="0">
              <pane ySplit="2" topLeftCell="A3" activePane="bottomLeft" state="frozen" />
         </sheetView>
    </sheetViews>`;
    
    $('worksheet', sheet).prepend(f1);
    },
    
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Super - many thanks for posting your solution.

    Allan

Sign In or Register to comment.