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

Dear monks, I use win32::Ole to generate several powerpoint slides with a ms graph within (one graph per slide).
i have no problem to create the graph, setup it and feed the datasheet from a database, but when there's more than one graph in the presentation and when i try to edit a graph in powerpoint, it is resetted ( as if a new graph was inserted with the menu 'Insert->Chart...' ).
It doesn't happen with a single graph on a single slide, the graph can be then correctly edited, the values and the setup i defined in my script are kept. Here's the way i create a new presentation:
########################################################### # # sub create_ppt_presentation # # create and return a new blank presentation # # $title is title for the presentation # ########################################################### sub create_ppt_presentation { my ($title) = @_; my ($PptApp, $Presentation, $Slide); trace("create_ppt_presentation: getting powerpoint.application obj +ect\n"); $PptApp = Win32::OLE-> GetActiveObject('PowerPoint.Application') || Win32::OLE-> new('PowerPoint.Application', 'Quit'); $PptApp-> {Visible} = IS_PPT_VISIBLE; $Presentation = $PptApp-> Presentations->Add(); return ($PptApp, $Presentation); }
Here's the way i use to create a slide and add a graph within, using the previously created presentation object:
$Slide = $Presentation-> Slides->Add({Index => $position, Layout => pp +LayoutBlank}); $Slide->{Name} = "test"; $graph_shape = $Slide->Shapes->AddOleObject({ Left => 10, Top => 40, Height => 450, Width => 650, ClassName => "MSGraph.Chart", Link => 0}); $graph = $graph_shape->OLEFormat->{Object}; # ms graph chart object # i can now work with $graph
Here's how i get the datasheet:
$datasheet = $graph->Application->{DataSheet}; $datasheet->Cells->ClearContents(); # i can now feed the datasheet with some datas # ... # after the settings of the datasheet's cells, free graph and data +sheet undef $datasheet; undef $graph;
After this, here's how i save the powerpoint presentation.
Note i dont't close presentation object, and quit the powerpoint application object at the end of the script. ( Maybe the issue is here ?? )
# $Presentaion is the powerpoint presentation object $Presentation->SaveAs("c:/test.ppt");
If anyone has an idea about this mysterious reset, i'll be sooo glad to hear it :o)

Replies are listed 'Best First'.
Re: [Win32::Ole] Ms graph in powerpoint generated file is resetted at edition
by traveler (Parson) on Nov 24, 2004 at 22:11 UTC
    I have played a lot with ppt and Perl, but not with MSChart. Some ideas: 1) Don't you need  $graph_shape->OLEFormat->Activate; to activate the graph? Maybe ppt does it on the close; 2) (probably a silly question), but do you give each slide a different Name?

    HTH, --traveler

      hello again,
      i tried the following things:
      - adding $graph_shape->OLEFormat->Activate; after the call to addOleObject.
      - adding a $Presentation->Close() and PptApp->Quit() at the end of the script.
      - adding a $graph_shape->Application->Quit() after a graph insertion.
      Alas it didn't change anything. i checked too if the slide have different names, theorically yes, i set the the $slide->{name} property according to an indice, but later i wasn't able to find the slide names i set in powerpoint. But I think it's ok with slide names.
      Moreover I found that if i insert 2 or 3 slides, there's always one that is ok, i can edit the values normally.

      So i investigate more, i'll post a comment if i found, but i 'm a bit pessimistic as i don't really know what is the root cause of this.