Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Unicode characters in Win32::Powerpoint

by iaw4 (Monk)
on Aug 26, 2011 at 15:57 UTC ( [id://922692]=perlquestion: print w/replies, xml ) Need Help??

iaw4 has asked for the wisdom of the Perl Monks concerning the following question:

dear perlmonks---

I need to put an alpha (and some other greek characters) into a powerpoint presentation. Windows XP. Powerpoint is 2007. perl is Strawberry 5.12.3. almost everything was just installed fairly recently, so there should be few legacy issues.

someone else told me this same code produces chinese character, someone else reported it working---I am just exasperated. How do I reliably get some basic Greek characters into my PowerPoint document?

#!/usr/bin/perl -w use strict; use warnings FATAL => qw{ uninitialized }; ## should be in -w!!! use utf8; use Win32::PowerPoint; my $ppt = Win32::PowerPoint->new; $ppt->new_presentation(); my $slide = $ppt->new_slide(); ## $slide is not used $ppt->add_text("Please print \x{03B1}"); $ppt->save_presentation('alpha.ppt'); $ppt->close_presentation();

Replies are listed 'Best First'.
Re: Unicode characters in Win32::Powerpoint
by angiehope (Pilgrim) on Aug 27, 2011 at 18:30 UTC
    Hi!
    As Win32::PowerPoint is not based on Unicode, I would suggest that you use Win32::OLE to create your PowerPoint file.
    You can set the encoding to UTF8 as described in Convert PowerPoint Presentation to Word Document with Win32::OLE and then create your PowerPoint file as described in Re: Using Win32::OLE and Excel - Tips and Tricks.
    Here's my own primitive example using information from the samples above and the Win32::PowerPoint source code:
    use strict; use utf8; use warnings; use File::Spec qw(rel2abs); use Win32::OLE qw( in CP_UTF8 ); Win32::OLE->Option( CP => CP_UTF8 ); $Win32::OLE::Warn = 3; # used File::Spec to save the file in my local directory # as Windows 7 is more restrictive about # users' file writing permissions than Windows XP my $filename = File::Spec->rel2abs("./unicode_example.ppt"); print( "Starting Powerpoint Object\n" ); my $power = Win32::OLE->GetActiveObject('Powerpoint.Application') || Win32::OLE->new('Powerpoint.Application', 'Quit'); my $ppt = $power->Presentations->Add(); # 12 = blank layout my $slide = $ppt->Slides->Add(1,12); # 1 = text in horizontal direction, the next two numbers describe the +position # and the last numbers the width and height of the box my $new_textbox = $slide->Shapes->AddTextbox(1,30,30,600,200); my $text_frame = $new_textbox->TextFrame; my $text_range = $text_frame->TextRange; $text_range->{Text} = "Please print \x{03B1},\x{03B2},\x{03B3}"; $ppt->SaveAs($filename);
    Hope this helps - I've successfully tested this under Windows 7, using Strawberry Perl 5.12.3 and Powerpoint 2010.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://922692]
Approved by Samy_rio
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-20 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found