gpt4 book ai didi

windows - 使用 Perl 将 UTF-8 字符放入 Excel?

转载 作者:可可西里 更新时间:2023-11-01 09:49:32 24 4
gpt4 key购买 nike

我的 XML 文档包含许多 UTF-8 字符,例如“É”和“é”,我正尝试将它们放入 Excel 中,但有些编码我无法获取。我正在使用 Win32::OLE 将数据放入 Excel。

我试过这个:

use Unicode::String qw(utf8 latin1 utf16le);
my $u = utf8($content);
$output = $u->utf16le;

但 Excel 单元格中唯一显示的是字符串的第一个字符(正确编码)。我在这里做错了什么?

最佳答案

您需要使用 Win32::OLE->Option 调用启用 utf8 编码。下面的代码对我有用(对于东欧字符):

use utf8;
use Win32::OLE qw(CP_UTF8);

Win32::OLE->Option(CP => CP_UTF8); # set utf8 encoding

my $excel = Win32::OLE->new('Excel.Application') or die $!;
$excel->{Visible} = 1;

my $wb = $excel->Workbooks->Add;
my $sheet = $wb->Sheets(1);

$sheet->Range('A1')->{Value} = 'Nějaký český text ďťň';

关于windows - 使用 Perl 将 UTF-8 字符放入 Excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com