Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

create a formatted table in ppt

by arundurai (Initiate)
on Mar 20, 2013 at 06:21 UTC ( #1024449=perlquestion: print w/ replies, xml ) Need Help??
arundurai has asked for the wisdom of the Perl Monks concerning the following question:

I can create a table in a ppt using the following code, but i want to include some changes in the design while creating it. The changes are to 1: Increase the width of the second column and align the table to the left extreme etc The code that I used to create a table is as follows

my $Slide = $Presentation->Slides->Add({Index=>$value , Layout=>ppLayo +utText}); $Slide->{Name} = "Slide111112"; my $Title=$Slide->Shapes->{Title}; $Title->TextFrame->TextRange->{Text} ="Weekly Analysis - Closing Ba +lance"; print( "Adding a 4 wide by 3 high table\n" ); my $table1 = $Slide->Shapes->AddTable( 5, # Rows 3, # Cols 50, # X-axis 110 # Y-axis ); my $columns1 = $table1->Table->Columns->Count; my $rows1 = $table1->Table->Rows->Count; my @sno = ("S No", 1, 2, 3, ''); my @ts = ("Ticket Status", "Open Rickets", "Closed Rickets", "Back Log +Tickets", "Grand Total"); my @tc =("Ticket Count","$op","$cl","$other","$tot"); for ( my $row = 0; $row < $rows1; $row++ ) { my $cell2 = $table1->Table->Rows($row+1)->Cells(1); my $textframe = $cell2->Shape->TextFrame; $textframe->TextRange->{Text} = "$sno[$row]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; ###################################################### my $cell3 = $table1->Table->Rows($row+1)->Cells(2); my $textframe1 = $cell3->Shape->TextFrame; $textframe1->TextRange->{Text} = "$ts[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "10"; ###################################################### my $cell4 = $table1->Table->Rows($row+1)->Cells(3); my $textframe2 = $cell4->Shape->TextFrame; $textframe2->TextRange->{Text} = "$tc[$row]"; $textframe2->TextRange->Font->{Name} = "Arial"; $textframe2->TextRange->Font->{Size} = "10"; }

Comment on create a formatted table in ppt
Download Code
Re: create a formatted table in ppt
by hdb (Parson) on Mar 20, 2013 at 08:36 UTC
    Hi arundurai, would you mind adding the code that creates $Presentation. I assume you use some Win32 modules?
    For every complex problem there is an answer that is clear, simple, and wrong. H. L. Mencken
Re: create a formatted table in ppt
by hdb (Parson) on Mar 20, 2013 at 11:55 UTC
    I usually use code like this
    print "Explore: ". $table1->Table->Columns(2)."\n"; for my $key (sort keys %{$table1->Table->Columns(2)}) { print "\t$key => ".$table1->Table->Columns(2)->$key."\n"; } print "Explore: ". $table1."\n"; for my $key (sort keys %{$table1}) { print "\t$key => ".$table1->$key."\n"; }
    to explore VB objects. Table width etc can be changed like this
    $table1->Table->Columns(2)->{'Width'} = 300; $table1->{'Left'} = 30; $table2->{'Top'} = 200;
    For every complex problem there is an answer that is clear, simple, and wrong. H. L. Mencken

      Thanks a lot H.L.Mencken I'm able to format my table now, and Yes I used Win32 to create a presentation. Now can I add a chart in PPT like creating a table, I have the data for the chart in a array. Just the command to cerate a chart in ppt would be very useful.. I have given the code that I'm using now, Please say how I can create a chart in the same slide which has a table

      my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| +Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; #my $Presentation = $PptApp->Presentations->Add(); my $Presentation = $PptApp->Presentations->Open({FileName=>'C:\Users\n +1013784\Desktop\New folder\weeklytemplate1.pptx',ReadOnly=>0}); my $value = 0; my $AfterSlide = "Agenda"; my $SlideIndex = 1; my $slides = Win32::OLE::Enum->new( $Presentation->Slides ); while ( my $slide = $slides->Next ) { print "Slide_Name : " . $slide->Name . "\n"; my $shapes = Win32::OLE::Enum->new( $slide->Shapes ); SHAPE: while ( my $shape = $shapes->Next ) { my $type = $shape->PlaceholderFormat->Type; if ( $type == ppPlaceholderTitle or $type == ppPlaceholderCent +erTitle or $type == ppPlaceholderVerticalTitle) { print "Title : |" . $shape->TextFrame->TextRange->text . " +|\n"; if($shape->TextFrame->TextRange->text eq $AfterSlide){ $value = $SlideIndex + 1; print "Put it on $SlideIndex\n"; } $SlideIndex++; last SHAPE; } } for (my $dev =0; $dev < $check ; $dev++){ my $Slide = $Presentation->Slides->Add({Index=>$value , Layout=>ppLayo +utText}); $Slide->{Name} = "111 + $dev"; my $Title=$Slide->Shapes->{Title}; $Title->TextFrame->TextRange->{Text} ="Weekly Metrics - Closed Tick +ets"; print( "Adding a 4 wide by 3 high table\n" ); my $table = $Slide->Shapes->AddTable( "$use", # Rows 8, # Cols 00, # X-axis 100 # Y-axis ); $table->Table->Columns(4)->{'Width'} = 300; $table->{'Left'} = 0; $table->{'Top'} = 100; my $columns = $table->Table->Columns->Count; my $rows = $table->Table->Rows->Count; my $cell = $table->Table->Rows(1)->Cells(2); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$ticketno[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(4); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$title[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(1); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$cdate[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(3); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$comp[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(6); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$priority[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(7); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$status[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(8); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$mdate[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; my $cell = $table->Table->Rows(1)->Cells(5); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$assigned[0]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; if ($dev == 0){ ; } else { $rows = $row + 11; } print $row; for ( my $arun = 1; $row < $rows; $row++ ) { ###################################################### if ($row == $count) {last;} if ($status[$row] eq "Closed" or $status[$row] eq "Resolved" o +r $status[$row] eq "Status"){ my $cell = $table->Table->Rows($arun+1)->Cells(2); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$ticketno[$row]"; $textframe->TextRange->Font->{Name} = "Arial"; $textframe->TextRange->Font->{Size} = "10"; ###################################################### my $cell1 = $table->Table->Rows($arun+1)->Cells(4); my $textframe1 = $cell1->Shape->TextFrame; $textframe1->TextRange->{Text} = "$title[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "10"; ###################################################### my $cell5 = $table->Table->Rows($arun+1)->Cells(1); my $textframe1 = $cell5->Shape->TextFrame; $textframe1->TextRange->{Text} = "$cdate[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "8"; ###################################################### my $cell6 = $table->Table->Rows($arun+1)->Cells(3); my $textframe1 = $cell6->Shape->TextFrame; $textframe1->TextRange->{Text} = "$comp[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "10"; ###################################################### my $cell7 = $table->Table->Rows($arun+1)->Cells(6); my $textframe1 = $cell7->Shape->TextFrame; $textframe1->TextRange->{Text} = "$priority[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "10"; ###################################################### my $cell8 = $table->Table->Rows($arun+1)->Cells(7); my $textframe1 = $cell8->Shape->TextFrame; $textframe1->TextRange->{Text} = "$status[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "10"; ###################################################### my $cell9 = $table->Table->Rows($arun+1)->Cells(8); my $textframe1 = $cell9->Shape->TextFrame; $textframe1->TextRange->{Text} = "$mdate[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "8"; ###################################################### my $cell19 = $table->Table->Rows($arun+1)->Cells(5); my $textframe1 = $cell19->Shape->TextFrame; $textframe1->TextRange->{Text} = "$assigned[$row]"; $textframe1->TextRange->Font->{Name} = "Arial"; $textframe1->TextRange->Font->{Size} = "8"; ###################################################### $arun++; } else{ $rows = $rows+1; } } $value++; if ($dev == ($check-2)){ $use = ($cl % 11)+1; } if ($dev == ($check-1)){ my $TextBox=$Slide->Shapes->AddTextbox({ Orientation=>1, Left=>200, Top=>500, Width=>250, Height=>250,}); $TextBox->TextFrame->TextRange->{Text} ="Total Tickets Closed = $cl +"; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-09-02 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (25 votes), past polls