Using "msoEncodingUTF8" with Win32::OLE in a perl script

233 Views Asked by At

I'm having a Perl script which saves a Word document as a HTML one. The following code works:

use strict;
use Win32::OLE::Const 'Microsoft Word';
[...]
$go_word_doc->SaveAs2({
    FileName => $gs_html_name,
    FileFormat => wdFormatFilteredHTML
    });

In order to encode the output file in UTF-8, I turned my command in this way:

$go_word_doc->SaveAs2({
    FileName => $gs_html_name,
    FileFormat => wdFormatFilteredHTML,
    Encoding => msoEncodingUTF8
    });

The problem is that "msoEncodingUTF8" is seen as a bareword, and I can't find anywhere what I'm supposed to add for it to work.

Could anyone help, please? Thanks in advance.

2

There are 2 best solutions below

1
ikegami On

The MsoEncoding Enum gives names to the Windows code pages. msoEncodingUTF8 is the name given to the UTF-8 code page, 65001.

use constant msoEncodingUTF8 => 65001;
0
JNM On

The following command will create msoEncodingUTF8 (and other constants) for you:

use Win32::OLE::Const 'Microsoft Office [0-9.]+ Object Library';