2016-05-03 17 views
4

anwenden Unter Code gelten alle Texte kursiv, aber ich möchte bestimmte Wörter kursiv anwenden.Wie man kursive Format in bestimmten Wörtern in Excel mit 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"; 

      } 
     } 

Antwort

4
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 =$1; my $val = $2; my $l = $3; 
       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"); 
      } 
     }