我正在用 Perl 生成一个 Word 文档,我想在生成的文本中包含度数符号 (°)。如果我像这样生成代码:
$cell .= qq/\xB0/;
$cell
这有效,并生成(对于的值55
):55°
然而,当我这样做时,perlcritic 向我抱怨并建议我改用这种结构:
$cell .= qq/\N{DEGREE SIGN}/;
这不起作用;它产生:55°
浏览我的代码perl -d
,我看到运行以下代码:
my $cell = 55;
$cell .= qq/\N{DEGREE SIGN}/; # the PBP way
print sprintf("%x\n", ord($_)) for split //, $cell;
my $cell = 55;
$cell .= qq/\xB0/; # the non-PBP way
print sprintf("%x\n", ord($_)) for split //, $cell;
结果是:
35
35
b0
我正在使用Win32::OLE将文本输出到 Word 文档:
my @column_headings = @{ shift $args->{'data'} };
my @rows = @{ $args->{'data'} };
my $word = Win32::OLE->new( 'Word.Application', 'Quit' );
my $doc = $word->Documents->Add();
my $select = $word->Selection;
$csv->combine(@column_headings);
$select->InsertAfter( $csv->string );
$select->InsertParagraphAfter;
for my $row (@rows) {
$csv->combine( @{$row} );
$select->InsertAfter( $csv->string );
$select->InsertParagraphAfter;
}
my $table =
$select->ConvertToTable( { 'Separator' => wdSeparateByCommas } );
$table->Rows->First->Range->Font->{'Bold'} = 1;
$table->Rows->First->Range->ParagraphFormat->{'Alignment'} =
wdAlignParagraphCenter;
@{ $table->Rows->First->Borders(wdBorderBottom) }{qw/LineStyle LineWidth/}
= ( wdLineStyleDouble, wdLineWidth100pt );
$doc->SaveAs( { 'Filename' => Cwd::getcwd . '/test.doc' } );
我能做些什么来摆脱多余的东西?