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

Hi Guys, I've just downloaded RTF module from CPAN, the installation went fine (more or less) I also was able to follow the examples at the POD and to write some words into a rtf file. However whan I tried to create a table I had some problems: I took the code from the attched example.
------
my $rtf = RTF::Writer->new_to_file("my.rtf"); my $decl = RTF::Writer::TableRowDecl->new('widths' => [1500,1900]); $rtf->row($decl, "Stuff", "Hmmm"); $rtf->row($decl, [\'\ul', 'Foo'], 'Bar', \'\bullet'); $rtf->row($decl, "Hooboy.");
------
In fact the example was a bit different it was somthing like this:
$h->row($decl, "Stuff", "Hmmm");
I figured that $h is a RTF object so I replaced it with my $rtf. The output at the file was hexdechineese (chines in hexa or somethibg similar).
I hope someone can help me on this one.
Thx in advance.

Replies are listed 'Best First'.
Re: starting RTF Writer
by wfsp (Abbot) on Mar 12, 2007 at 16:18 UTC
    Hi weirat,

    (on winxp and using MS Word to open the rtf)

    I could only get the example from the docs to work if I added an extra number to the widths (but see update2 below).

    This of course produced a three column, three row table. The docs show a table with: first row two column, second row three columns and third row two columns.

    The underline and the bullet showed fine.

    hth

    #!/usr/local/bin/perl use strict; use warnings; use RTF::Writer; my $rtf = RTF::Writer->new_to_file("greetings.rtf"); $rtf->prolog( 'title' => "Greetings, hyoomon" ); my $decl = RTF::Writer::TableRowDecl->new('widths' => [1500,1900, 1500 +]); $rtf->row($decl, "Stuff", "Hmmm"); $rtf->row($decl, [\'\ul', 'Foo'], 'Bar', \'\bullet'); $rtf->row($decl, "Hooboy.");
    update:
    Forgot to say that it didn't work at all without the $rtf->prolog(...) call.

    update2:
    A bit more fiddling and the following did reproduce the table shown in the docs

    #!/usr/local/bin/perl use strict; use warnings; use RTF::Writer; my $rtf = RTF::Writer->new_to_file("greetings.rtf"); $rtf->prolog( 'title' => "Greetings, hyoomon" ); my $decl; $decl = RTF::Writer::TableRowDecl->new('widths' => [1500,1900]); $rtf->row($decl, "Stuff", "Hmmm"); $decl = RTF::Writer::TableRowDecl->new('widths' => [1500,1900,1500]); $rtf->row($decl, [\'\ul', 'Foo'], 'Bar', \'\bullet'); $decl = RTF::Writer::TableRowDecl->new('widths' => [1500,1900]); $rtf->row($decl, "Hooboy.");
Re: starting RTF Writer
by diotalevi (Canon) on Mar 12, 2007 at 16:25 UTC

    It sounds as if you are using it correctly. I'd consider closing the rtf stream to see if that helps. I'd also try opening the document in a few different readers to see if it looks sane. For what its worth, I just tried the example myself and OpenOffice Writer didn't seem to think it was proper RTF either.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: starting RTF Writer
by ikkon (Monk) on Mar 21, 2007 at 19:20 UTC
    not sure if its too late but I build a function to help with the table creation, probably could be better but works for now
    my $tableVal2 = [2500,1900,1200, 1400]; my @tableData2 = ( ['this', "bnlut", 'jhsdfhjsa', 'thing'], ["that", "this", 'kjhsadfh', 'ben'], ["me", "none", 'slhdfjhsf', 'prat'], ); &table($tableVal2, @tableData2); ## calls the table function which + uses the array for values sub table(){ my($localVal, @localData) = @_; my $decl = RTF::Writer::TableRowDecl->new('widths' => $localVa +l ); $fh->row($decl, @$_) for @localData; }