[Important] personnaliser graphique powerpoint 2007

cs_miche53 Messages postés 8 Date d'inscription mercredi 10 mars 2004 Statut Membre Dernière intervention 5 avril 2007 - 4 avril 2007 à 17:12
cs_olecossois Messages postés 18 Date d'inscription jeudi 13 février 2003 Statut Membre Dernière intervention 12 mars 2008 - 12 déc. 2007 à 14:13
Bonjour à tous,

Je voudrais savoir si il quelqu'un saurait comment modifier l'aspect d'un graphique et ces données dans powerpoint sous vb.net.

J'arrive à ajouter un graphique mais je n'arrive pas à personnliser son aspect et ces données.
lorsque le powerpoint ce génére, il m'ouvre en même temps une feuille excel comprenant des données de base. Voici un bout de code:

Dim myGraph As Microsoft.Office.Interop.PowerPoint.Shape
myGraph = oShapes.AddChart(Microsoft.Office.Core.XlChartType.xlDoughnut, 150, 150, 480, 320)
myGraph.ThreeD.Visible = True
myGraph.ThreeD.SetThreeDFormat(Microsoft.Office.Core.MsoPresetThreeDFormat.msoThreeD15)

NB:  les deux dernière lignes ne font rien du tout.

j'avais plus de choix en faisant :

Dim oChart As Microsoft.Office.Interop.Graph.Chart
oShape = oShapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart")
oChart.ChartType = Graph.XlChartType.xlDoughnut
oChart.ApplyDataLabels()
Dim dataGraph = oChart.Application.DataSheet
dataGraph.Cells.Clear()
dataGraph.Cells(1, 1).Value = "Jours"
dataGraph.Cells(1, 2).Value = "Lu"
dataGraph.Cells(1, 3).Value = "Ma"
dataGraph.Cells(1, 4).Value = "Me"
dataGraph.Cells(1, 5).Value = "Je"
dataGraph.Cells(1, 6).Value = "Ve"
dataGraph.Cells(1, 7).Value = "Sa"
dataGraph.Cells(1, 8).Value = "Di"
dataGraph.Cells(2, 1).Value = "Valeurs"
dataGraph.Cells(2, 2).Value = 10
dataGraph.Cells(2, 3).Value = 20
dataGraph.Cells(2, 4).Value = 30
dataGraph.Cells(2, 5).Value = 50
dataGraph.Cells(2, 6).Value = 80
dataGraph.Cells(2, 7).Value = 100
dataGraph.Cells(2, 8).Value = 30

Mais avec ça les graphiques sont de types office 2003 et pas beau.

Je voudrais faire la même chose mais en utilisant addChart pour créer mon garphique

Merci d'avance de votre aide.

PS: Ca fait quelques jours que je suis deçu et là franchement je trouve pas Help Me

5 réponses

cs_miche53 Messages postés 8 Date d'inscription mercredi 10 mars 2004 Statut Membre Dernière intervention 5 avril 2007
5 avril 2007 à 10:40
personne n'a d'idée :-(

Une petite piste car je ne vaois vraiement pas du tout
0
cs_Acalon Messages postés 2 Date d'inscription mercredi 30 juillet 2003 Statut Membre Dernière intervention 11 décembre 2007
15 avril 2007 à 23:15
Bonjour miche.

Je vais vraiment être désagréable, mais en fait, tu ne peux pas :( . L'implémentation de la propriété chart n'est pas exposée dans le DOM pourtant elle existe dans la doc. La doc fournie avec office est incomplète, il faut consulter la doc online. Et la doc online sur MSDN n'est pas réalisée : en gros, du n'importe quoi de la part des développeurs qui ont complètement baclée cette partie. Tu verras deux ou trois posts sur les newsgroup à ce propos (office automation)

sur PPTFaq.com, le type conseille, si on fait du charting sous office 2007 en automation, de "changer de ville" ;)

Voila, on est tous dasn le même cas, c la mémerde. bon courage.

Ah oui, aussi intéressant, j'ai fais des benchs et l'automation est VRAIMENT trop long. J'ai contacté [mailto:pierlag@microsoft.com pierlag@microsoft.com] qui m'a répondu à chaque fois de travers ou en refusant visiblement de comprendre que cette putain de propriété chart n'est pas implémenté : ils s'en foutent?

enfin bref, tout ceci est vraiment dommage.

Si tu as des nouvelles, ou une solution, tiens moi au courant :
[mailto:cadherins@msn.com cadherins@msn.com
]
A+
0
cs_olecossois Messages postés 18 Date d'inscription jeudi 13 février 2003 Statut Membre Dernière intervention 12 mars 2008
11 déc. 2007 à 17:11
Voici ce que j'ai réussi à trouve

mon  AddChart((Office::XlChartType) Office::xlBarClustered,150,150,480,320);

je developpe en C++, c'est un peu différent mais bon.

Olivier
0
cs_Acalon Messages postés 2 Date d'inscription mercredi 30 juillet 2003 Statut Membre Dernière intervention 11 décembre 2007
11 déc. 2007 à 17:36
Bonjour Olecossois, 

Peux tu préciser ton code? Il n'y a pas d'accesseurs dans le DOM nommés AddChart sur l'objet Slide ou sur la collection Shapes. (toujorus dans PowerPoint 2007, car ton graphe est un graphe excel) Comment peux tu par ailleurs appliquer la feuille de données?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_olecossois Messages postés 18 Date d'inscription jeudi 13 février 2003 Statut Membre Dernière intervention 12 mars 2008
12 déc. 2007 à 14:13
Comme je vous disait, c du C++.

Mais j'arrive a avoir un Graph avec Office 2007, les nouveaux bien sur.

Le bouton1 sert à mes test Office 2007 (la je n'arrive qu'a afficher le graphique)
Le bouton2 sert à mes test Offce 2003 (la j'arrive à modifier les données en plus)

Mon but est de modifier les données du graphique en Office 2007

// maindlg.cpp : implementation of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "resource.h"


#include "maindlg.h"


#include <string>
using namespace std;


#define OFFICE2007


#ifdef OFFICE2007
 #define GRAPH_LIB "C:\Program Files\Microsoft Office\Office12\graph.exe"
 #define EXCEL_LIB "C:\Program Files\Microsoft Office\Office12\excel.exe" rename("DialogBox", "myDialogBox") rename("RGB", "myRGB")
 // accès aux services de office et powerpoint
 #import "C:\Program Files\Fichiers communs\Microsoft Shared\Office12\mso.dll" named_guids
 #import "C:\Program Files\Fichiers communs\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" raw_interfaces_only, no_namespace
 //using namespace VBIDE;
 
 #import "C:\Program Files\Microsoft Office\Office12\msppt.olb"


 #import GRAPH_LIB rename("XlChartType", "GXlChartType")
 #import EXCEL_LIB rename("DialogBox", "myDialogBox") rename("RGB", "myRGB") rename("XlChartType", "XXlChartType")
#endif
using namespace Office;




LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
 // center the dialog on the screen
 CenterWindow();


 // set icons
 HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
  IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
 SetIcon(hIcon, TRUE);
 HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
  IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
 SetIcon(hIconSmall, FALSE);


 return TRUE;
}


LRESULT CMainDlg::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
 CSimpleDialog dlg;
 dlg.DoModal();
 return 0;
}


LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
 // TODO: Add validation code
 EndDialog(wID);
 return 0;
}


LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
 EndDialog(wID);
 return 0;
}


LRESULT CMainDlg::OnClickedButton1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
 CoInitialize(NULL);


 try
 {
  PowerPoint::_ApplicationPtr app;
  
  HRESULT hr;
  hr = app.GetActiveObject("PowerPoint.Application");
  
  if(FAILED(hr))
  {
   hr = app.CreateInstance("PowerPoint.Application");
   if(FAILED(hr))
   {
    return -1;
   }


  } 


  hr = app->put_Visible(msoTrue);  
  if(FAILED(hr))
  {
   return -1;
  }
  
  


  PowerPoint::PresentationsPtr presentations;
  PowerPoint::_PresentationPtr presentation;
  PowerPoint::SlidesPtr   slides;
  PowerPoint::_SlidePtr   slide;


  PowerPoint::DocumentWindowPtr documentwindow;
  PowerPoint::SelectionPtr   selection;
  PowerPoint::SlideRangePtr   sliderange;


  int idxSlide=0;


  hr = app->get_Presentations(&presentations);
  if(FAILED(hr))
   return false;


  hr = app->get_ActivePresentation(&presentation);
  if(FAILED(hr))
  {
   presentation = presentations->Add(msoTrue);
  }


  hr = presentation->get_Slides(&slides);
  if(FAILED(hr))
   return false;


  slide = slides->Add(idxSlide+1, PowerPoint::ppLayoutBlank);


  PowerPoint::ShapePtr oShape;
  Graph::ChartPtr oChart;


  slide->Shapes->raw_AddChart((Office::XlChartType) Office::xlBarClustered,150,150,480,320,&oShape);
  
 }
 catch (runtime_error& e)
 {
  MessageBox(e.what(),"test",MB_OK);
  return 1;
 }
 catch (_com_error & e)
 {
  MessageBox(e.ErrorMessage(),"test",MB_OK);
  return 1;
 }
 catch (...)
 {
  MessageBox("unknown error occured","test",MB_OK);
  return 1;
 }


 CoUninitialize();
 return 0;
}




LRESULT CMainDlg::OnClickedButton2(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
 CoInitialize(NULL);


 try
 {
  PowerPoint::_ApplicationPtr app;
  
  HRESULT hr;
  hr = app.GetActiveObject("PowerPoint.Application");
  
  if(FAILED(hr))
  {
   hr = app.CreateInstance("PowerPoint.Application");
   if(FAILED(hr))
   {
    return -1;
   }


  } 


  hr = app->put_Visible(msoTrue);  
  if(FAILED(hr))
  {
   return -1;
  }
  
  


  PowerPoint::PresentationsPtr presentations;
  PowerPoint::_PresentationPtr presentation;
  PowerPoint::SlidesPtr   slides;
  PowerPoint::_SlidePtr   slide;


  PowerPoint::DocumentWindowPtr documentwindow;
  PowerPoint::SelectionPtr   selection;
  PowerPoint::SlideRangePtr   sliderange;


  int idxSlide=0;


  
  hr = app->get_Presentations(&presentations);
  if(FAILED(hr))
   return false;


  hr = app->get_ActivePresentation(&presentation);
  if(FAILED(hr))
  {
   presentation = presentations->Add(msoTrue);
  }


  hr = presentation->get_Slides(&slides);
  if(FAILED(hr))
   return false;


  slide = slides->Add(idxSlide+1, PowerPoint::ppLayoutBlank);


  PowerPoint::ShapePtr oShape;
  Graph::ChartPtr oChart;
  
  hr = slide->Shapes->raw_AddOLEObject(150, 150, 480, 320, (_bstr_t) "MSGraph.chart", (_bstr_t) "", msoFalse, (_bstr_t) "", 0, (_bstr_t)


"",msoFalse, &oShape);


  oShape->PutVisible(msoFalse);


  PowerPoint::OLEFormatPtr olefmt;


  hr = oShape->get_OLEFormat(&olefmt);
  if(FAILED(hr))
   return false;


  hr = olefmt->get_Object( (struct IDispatch **) &oChart);


  oChart->PutChartType(Graph::xlBarClustered);
    
  Graph::DataSheetPtr dataGraph;


  dataGraph = oChart->Application->GetDataSheet();
  dataGraph->GetColumns()->Clear();


  dataGraph->GetCells()->Clear();


  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (1)), _variant_t((_bstr_t) "Jours") );


  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (2)), _variant_t((_bstr_t) "Lu") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (3)), _variant_t((_bstr_t) "Ma") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (4)), _variant_t((_bstr_t) "Me") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (5)), _variant_t((_bstr_t) "Je") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (6)), _variant_t((_bstr_t) "Ve") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (7)), _variant_t((_bstr_t) "Sa") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (1)), _variant_t((long) (8)), _variant_t((_bstr_t) "Di") );


  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (1)), _variant_t((_bstr_t) "Valeurs") );


  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (2)), _variant_t((_bstr_t) "10") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (3)), _variant_t((_bstr_t) "20") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (4)), _variant_t((_bstr_t) "30") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (5)), _variant_t((_bstr_t) "40") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (6)), _variant_t((_bstr_t) "50") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (7)), _variant_t((_bstr_t) "60") );
  dataGraph->GetCells()->PutItem( _variant_t((long) (2)), _variant_t((long) (8)), _variant_t((_bstr_t) "70") );


         oShape->PutVisible(msoTrue);
       
  
  
  //DataSheet dataGraph = oChart.Application.DataSheet;
  
   /*
   


            Object oMissing = Type.Missing;


 


            Microsoft.Office.Interop.Graph.Chart oChart;


            PowerPoint.Shape oShape = slide.Shapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart", "",
   Microsoft.Office.Core.MsoTriState.msoFalse, "", 0, "",Microsoft.Office.Core.MsoTriState.msoFalse);


            oChart = (Microsoft.Office.Interop.Graph.Chart)oShape;


            oChart.ChartType = XlChartType.xlDoughnut;


            //oChart.ApplyDataLabels();


            DataSheet dataGraph = oChart.Application.DataSheet;


            dataGraph.Cells.Clear();


            dataGraph.Cells[1, 1]= "Jours";


            dataGraph.Cells[1, 2]= "Lu";


            dataGraph.Cells[1, 3]= "Ma";


            dataGraph.Cells[1, 4]= "Me";


            dataGraph.Cells[1, 5]= "Je";


            dataGraph.Cells[1, 6]= "Ve";


            dataGraph.Cells[1, 7]= "Sa";


            dataGraph.Cells[1, 8]= "Di";


            dataGraph.Cells[2, 1]= "Valeurs";


            dataGraph.Cells[2, 2]= 10;


            dataGraph.Cells[2, 3]= 20;


            dataGraph.Cells[2, 4]= 30;


            dataGraph.Cells[2, 5]= 50;


            dataGraph.Cells[2, 6]= 80;


            dataGraph.Cells[2, 7]= 100;


            dataGraph.Cells[2, 8]= 30;


   
*/


  
 }
 catch (runtime_error& e)
 {
  MessageBox(e.what(),"test",MB_OK);
  return 1;
 }
 catch (_com_error & e)
 {
  MessageBox(e.ErrorMessage(),"test",MB_OK);
  return 1;
 }
 catch (...)
 {
  MessageBox("unknown error occured","test",MB_OK);
  return 1;
 }


 CoUninitialize();
 return 0;
}
0
Rejoignez-nous