Excel-Writer-XLSX

 view release on metacpan or  search on metacpan

lib/Excel/Writer/XLSX/Examples.pm  view on Meta::CPAN

        subject  => 'With document properties',
        author   => 'John McNamara',
        manager  => 'Dr. Heinz Doofenshmirtz',
        company  => 'of Wolves',
        category => 'Example spreadsheets',
        keywords => 'Sample, Example, Properties',
        comments => 'Created with Perl and Excel::Writer::XLSX',
        status   => 'Quo',
    );
    
    
    $worksheet->set_column( 'A:A', 70 );
    $worksheet->write( 'A1', qq{Select 'Office Button -> Prepare -> Properties' to see the file properties.} );
    
    $workbook->close();
    
    __END__


Download this example: L<http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.15/examples/properties.pl>

=head2 Example: protection.pl



Example of cell locking and formula hiding in an Excel worksheet via
the Excel::Writer::XLSX module.


SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later


=begin html

<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/protection.jpg" width="640" height="420" alt="Output from protection.pl" /></center></p>

=end html

Source code for this example:

    #!/usr/bin/perl
    
    ########################################################################
    #
    # Example of cell locking and formula hiding in an Excel worksheet via
    # the Excel::Writer::XLSX module.
    #
    # Copyright 2000-2025, John McNamara, jmcnamara@cpan.org
    #
    # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
    #
    
    use strict;
    use warnings;
    use Excel::Writer::XLSX;
    
    my $workbook  = Excel::Writer::XLSX->new( 'protection.xlsx' );
    my $worksheet = $workbook->add_worksheet();
    
    # Create some format objects
    my $unlocked = $workbook->add_format( locked => 0 );
    my $hidden   = $workbook->add_format( hidden => 1 );
    
    # Format the columns
    $worksheet->set_column( 'A:A', 45 );
    $worksheet->set_selection( 'B3' );
    
    # Protect the worksheet
    $worksheet->protect();
    
    # Examples of cell locking and hiding.
    $worksheet->write( 'A1', 'Cell B1 is locked. It cannot be edited.' );
    $worksheet->write_formula( 'B1', '=1+2', undef, 3 );    # Locked by default.
    
    $worksheet->write( 'A2', 'Cell B2 is unlocked. It can be edited.' );
    $worksheet->write_formula( 'B2', '=1+2', $unlocked, 3 );
    
    $worksheet->write( 'A3', "Cell B3 is hidden. The formula isn't visible." );
    $worksheet->write_formula( 'B3', '=1+2', $hidden, 3 );
    
    $worksheet->write( 'A5', 'Use Menu->Tools->Protection->Unprotect Sheet' );
    $worksheet->write( 'A6', 'to remove the worksheet protection.' );
    
    $workbook->close();
    
    __END__
    


Download this example: L<http://cpansearch.perl.org/src/JMCNAMARA/Excel-Writer-XLSX-1.15/examples/protection.pl>

=head2 Example: rich_strings.pl



An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
strings with multiple formatting.


SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later


=begin html

<p><center><img src="http://jmcnamara.github.io/excel-writer-xlsx/images/examples/rich_strings.jpg" width="640" height="420" alt="Output from rich_strings.pl" /></center></p>

=end html

Source code for this example:

    #!/usr/bin/perl
    
    #######################################################################
    #
    # An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
    # strings with multiple formatting.
    #
    # Copyright 2000-2025, John McNamara, jmcnamara@cpan.org
    #
    # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
    #
    
    use strict;
    use warnings;
    use Excel::Writer::XLSX;
    
    my $workbook  = Excel::Writer::XLSX->new( 'rich_strings.xlsx' );
    my $worksheet = $workbook->add_worksheet();
    
    $worksheet->set_column( 'A:A', 30 );
    
    # Set some formats to use.
    my $bold   = $workbook->add_format( bold        => 1 );
    my $italic = $workbook->add_format( italic      => 1 );
    my $red    = $workbook->add_format( color       => 'red' );
    my $blue   = $workbook->add_format( color       => 'blue' );



( run in 2.099 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )