<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

#######################################################################
#
# An Excel::Writer::XLSX example showing how to use "rich strings", i.e.,
# strings with multiple formatting.
#
# Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
#

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

my $workbook  = Excel::Writer::XLSX-&gt;new( 'rich_strings.xlsx' );
my $worksheet = $workbook-&gt;add_worksheet();

$worksheet-&gt;set_column( 'A:A', 30 );

# Set some formats to use.
my $bold   = $workbook-&gt;add_format( bold        =&gt; 1 );
my $italic = $workbook-&gt;add_format( italic      =&gt; 1 );
my $red    = $workbook-&gt;add_format( color       =&gt; 'red' );
my $blue   = $workbook-&gt;add_format( color       =&gt; 'blue' );
my $center = $workbook-&gt;add_format( align       =&gt; 'center' );
my $super  = $workbook-&gt;add_format( font_script =&gt; 1 );


# Write some strings with multiple formats.
$worksheet-&gt;write_rich_string( 'A1',
    'This is ', $bold, 'bold', ' and this is ', $italic, 'italic' );

$worksheet-&gt;write_rich_string( 'A3',
    'This is ', $red, 'red', ' and this is ', $blue, 'blue' );

$worksheet-&gt;write_rich_string( 'A5',
    'Some ', $bold, 'bold text', ' centered', $center );

$worksheet-&gt;write_rich_string( 'A7',
    $italic, 'j = k', $super, '(n-1)', $center );

$workbook-&gt;close();

__END__
</pre></body></html>