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

标签 windows perl excel encoding

我的 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/

相关文章:

c# - 在 Windows 中如何从 USB HID 设备获取原始描述符数据?

windows - bash Windows 10 上的 ssh 远程访问

c++ - 在 linux 上为 windows 编译

windows - 从 Perl 运行批处理文件(Windows 中的 Activestate perl)

当包装在 perl DBI 中时,MySQL 查询似乎给出了不同的结果

vba - 在漫长的过程中如何通知用户?

java - Apache POI - 无法让折线图值出现在辅助轴中

windows - 如何中断 Windows 上的选择调用?

perl - 在 Perl 5 中是否有一个优雅的 zip 来交错两个列表?

excel公式剥离html