Search code examples
perlperl-module

Excel::Writer::XLSX - howto freeze first line


I'm using the perl module Excel::Writer::XLSX. The following code snippet creates a header line in the result file.

use strict;
use warnings;
use Excel::Writer::XLSX;

my $workbook  = Excel::Writer::XLSX->new("myExcel.xlsx");
my $worksheet = $workbook->add_worksheet("Sheet1");
my $ccnt = 0;
foreach my $entry (('Head1','Head2','Head3')) {
    $worksheet->write(0,$ccnt++,$entry);
}
$workbook->close();

Now, I'd like to fix that first line to keep it visible while downscrolling. Although there is a bunch of good documentation on CPAN, I didn't find how to manage this.


Solution

  • Answering my own question as victim of a wrong translation: The task is to freeze the first line of the Excel-sheet, not to fix it. (The question title already mentioned this :-(

    The solution is as simple as follows. Add

    $worksheet->freeze_panes(1);
    

    right after creation of the worksheet.