如何使用 perl 在 excel 中的特定单词中应用斜体格式

how to apply italic format in specific words in excel using perl

下面的代码将所有文本应用为斜体,但我想将特定单词应用为斜体。

use Win32::OLE;
    foreach my $key (keys %main){ 
            my @cnt = @{$main{$key}};
            my $count = 1;
            foreach my $cnt (@cnt){
                ++$count;
                $cnt =~ s{\n}{}g;
                $sheet -> Range("$key$count") -> {NumberFormat} = "\@"; 
                $sheet->Range("$key$count")->{Value} = "$cnt";
                $sheet -> Range("$key$count:${range}1") -> Columns -> {AutoFit} = "True";
                $sheet->Range("A1:${range}1")->Font->{Italic} = "True";

            }
        }
use Excel::Writer::XLSX;
foreach my $key (keys %main){ 
        my @cnt = @{$main{$key}};
        my $count = 1;

        foreach my $cnt (@cnt){
            ++$count;
            $cnt =~ s{\n}{}g;
            $cnt = decode_entities($cnt);
            $cnt =~ s{&del;}{}igs;

            $worksheet->write_string( "$key$count", "$cnt");
            $worksheet->set_column( "$key$count", undef);
            my $bold   = $workbook->add_format( bold   => 1 );
            my $italic = $workbook->add_format( italic => 1 );
            while($cnt =~ m{^(.*)<emphasis role="italic">(.*?)</emphasis>(.*)}igs){
                my $f =; my $val = ; my $l = ; 
                my $gls1 = $gls; 
                $gls1 =~ s{\}{\/}ig;
                $val ="<i>$val</i>" if($file =~ m{^\Q$gls1\E$}i);
                $worksheet->write_rich_string( "$key$count","$f" ,$italic,$val,  "$l");
            }
        }