module OpenOffice::OODoc fails with Unicode characters

D

David Sudlow

When I try to write out a utf8 string using extendText(),
appendParagraph or other methods with the OpenOffice::OODoc module, I
get the following error:

Cannot decode string with wide characters at C:/Perl/lib/Encode.pm line 162.

I have the localEncoding set to utf8 as I should and it reads in fine
from an office document containing utf8 characters.

Here is a short but complete script that illustrates the issue:

use strict;
use warnings;
use OpenOffice::OODoc;

ooLocalEncoding('utf8');

my $archive = OpenOffice::OODoc::File->new(
"my_document.odt",
create => "text");


my $text = ooDocument(
archive => $archive,
member => 'content'
);

$text->appendParagraph(text => "hello\x{100}");

$archive->save();
 
D

David Sudlow

Christian said:
Insert
use Encode qw(encode);
here...


...and make this:


my $hello = encode('utf-8', "hello\x{100}");
$text->appendParagraph(text => $hello);


and things should work. appendParagraph() seemingly expects the
text parameter to be a series of utf-8 octets, while "hello\x{100}"
creates a string with a wide character in Perl's native encoding.

HTH
-Chris

Thanks, this works (in my real code as well as the example). It feels
like a bit of a kludge though. Shouldn't there be a way to tell perl to
pass utf-8 strings without the explicit conversion, given that I am
reading in utf8 and passing it to a function that expects utf8?

Would you consider this a perl issue or an OpenOffice::OODoc issue an
'Encode' issue or 'expected behaviour'?

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top