IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Piloter un graphique word depuis vb.net


Sujet :

VB.NET

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Novembre 2013
    Messages : 44
    Points : 27
    Points
    27
    Par défaut Piloter un graphique word depuis vb.net
    Bonjour,

    Pour terminer mon projet, je dois sortir toutes les données de mon appli sous la forme d'un document word.

    Pas de souci pour tout ce qui est texte, tableaux, etc.. même si la mise en page est relativement longue.

    Par contre, je me heurte à une grosse difficulté lorsque j'essaye de créer un graphique. Il semble que les fonctions d'interopérabilité ne soit pas aussi développée que sur le reste.
    J'arrive à créer un graphique

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     
            Dim oWord As Word.Application
            Dim oDoc As Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Add
     
    Dim graph = oDoc.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlXYScatter)
    Par contre, maintenant je voudrais changer le type de graphique, et ajouter une série de données que je possède, et impossible de trouver les commandes.
    Quelqu'un a déjà fait ça?

  2. #2
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 904
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 904
    Points : 10 168
    Points
    10 168
    Billets dans le blog
    36
    Par défaut
    Bonjour


    Citation Envoyé par chtinis Voir le message
    Bonjour,
    et impossible de trouver les commandes.
    Ben, dans l'aide de VBA Word.

    Référence du développeur Word
    Chart, membres de l’objet
    et dans MSDN

    https://www.microsoft.com/en-us/down....aspx?id=40326

    https://msdn.microsoft.com/fr-fr/library/ee861527.aspx

    https://msdn.microsoft.com/fr-fr/library/ff837519.aspx

    https://msdn.microsoft.com/fr-fr/library/dn911480.aspx

    https://msdn.microsoft.com/fr-fr/lib.../dn467914.aspx
    À ma connaissance, le seul personnage qui a été diagnostiqué comme étant allergique au mot effort. c'est Gaston Lagaffe.

    Ô Saint Excel, Grand Dieu de l'Inutile.

    Excel n'a jamais été, n'est pas et ne sera jamais un SGBD, c'est pour cela que Excel s'appelle Excel et ne s'appelle pas Access junior.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Novembre 2013
    Messages : 44
    Points : 27
    Points
    27
    Par défaut
    Si c'était si facile, j'aurais pas demandé de l'aide.

    L'enregistrement des macros dans word étant pas terrible, il est relativement difficile de trouver ce qui se passe réellement derrière quand on ajoute un graphique.

    J'ai trouvé un début de réponse sur un forum, je teste demain, mais c'est loin d'être aussi trivial que prévu. Je pensais juste avoir à ajouter des séries, comme sous excel, ou sous les chart VB, mais ce n'est pas le cas:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
       2:  word = new Word.Application();
       3:  word.Visible = true;
       4:  Word.Document doc = word.Documents.Add(ref missing, ref missing, ref missing, ref missing);
     
       5:  Word.Chart wdChart = doc.InlineShapes.AddChart(Microsoft.Office.Core.XlChartType.xl3DColumn , ref missing).Chart;
     
       6:  Word.ChartData chartData = wdChart.ChartData;
     
       7:  Excel.Workbook dataWorkbook = (Excel.Workbook)chartData.Workbook;
       8:  Excel.Worksheet dataSheet = (Excel.Worksheet)dataWorkbook.Worksheets[1];
     
       9:  Excel.Range tRange = dataSheet.Cells.get_Range("A1", "B5");
      10:  Excel.ListObject tbl1 = dataSheet.ListObjects["Table1"];
      11:  tbl1.Resize(tRange);
     
      12:  ((Excel.Range)dataSheet.Cells.get_Range("A2", missing)).FormulaR1C1 = "Bikes";
      13:  ((Excel.Range)dataSheet.Cells.get_Range("A3", missing)).FormulaR1C1 = "Accessories";
      14:  ((Excel.Range)dataSheet.Cells.get_Range("A4", missing)).FormulaR1C1 = "Repairs";
      15:  ((Excel.Range)dataSheet.Cells.get_Range("A5", missing)).FormulaR1C1 = "Clothing";
      16:  ((Excel.Range)dataSheet.Cells.get_Range("B2", missing)).FormulaR1C1 = "1000";
      17:  ((Excel.Range)dataSheet.Cells.get_Range("B3", missing)).FormulaR1C1 = "2500";
      18:  ((Excel.Range)dataSheet.Cells.get_Range("B4", missing)).FormulaR1C1 = "4000";
      19:  ((Excel.Range)dataSheet.Cells.get_Range("B5", missing)).FormulaR1C1 = "3000";
     
      20:  wdChart.ChartTitle.Font.Italic = true;
      21:  wdChart.ChartTitle.Font.Size = 18;
      22:  wdChart.ChartTitle.Font.Color = Color.Black.ToArgb();
      23:  wdChart.ChartTitle.Text = "2007 Sales";
      24:  wdChart.ChartTitle.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
     
      25:  wdChart.ChartTitle.Format.Line.ForeColor.RGB = Color.Black.ToArgb();
     
      26:  wdChart.ApplyDataLabels(Word.XlDataLabelsType.xlDataLabelsShowLabel, missing, missing, missing, missing, missing, missing, missing, missing, missing);
     
      27:  dataWorkbook.Application.Quit();

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Novembre 2013
    Messages : 44
    Points : 27
    Points
    27
    Par défaut
    Pour ceux que ca intéresse, voici la résolution pour permettre de piloter complètement un graphique sous word.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
     
       oChart = odoc.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlXYScatterSmoothNoMarkers, , , , , orng).Chart
                Dim chartdata As Word.ChartData = oChart.ChartData
                Dim dataWorkbook As Excel.Workbook = chartdata.Workbook
                Dim datasheet As Excel.Worksheet = dataWorkbook.Worksheets(1)
                Dim tRange As Excel.Range = datasheet.Cells.Range("A1", "B" & mon_objet.mesures.Count)
     
                Dim tbl1 As Excel.ListObject = datasheet.ListObjects("Tableau1")
     
                tbl1.Resize(tRange)
     
                datasheet.Cells.Range("A1").FormulaR1C1 = "lbl1"
                datasheet.Cells.Range("B1").FormulaR1C1 = "lbl2"
                For i = 0 To mon_objet.mesures.Count - 1
     
                    datasheet.Cells.Range("A" & i + 2).FormulaR1C1 = mon_objet.mesures(i).abscisse_graph
                    datasheet.Cells.Range("B" & i + 2).FormulaR1C1 = mon_objet.mesures(i).ordonnee_graph
     
                Next
                pause(2000)
     
                oChart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
                oChart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueAxisTitleRotated)
                oChart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementLegendNone)
                oChart.Axes(Word.XlAxisType.xlCategory, Word.XlAxisGroup.xlPrimary).AxisTitle.Text = "lbl1"
                oChart.Axes(Word.XlAxisType.xlValue, Word.XlAxisGroup.xlPrimary).AxisTitle.Text = "lbl2"
                oChart.Axes(Word.XlAxisType.xlCategory, Word.XlAxisGroup.xlPrimary).minimumscale = 0.0
                oChart.Axes(Word.XlAxisType.xlValue, Word.XlAxisGroup.xlPrimary).MinimumScale = 0.0
                oChart.ChartTitle.Font.Size = 18
                oChart.ChartTitle.Font.Color = Color.Black.ToArgb()
                oChart.ChartTitle.Text = "mon_titre"
                oChart.ChartTitle.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
                oChart.ChartTitle.Format.Line.ForeColor.RGB = Color.Black.ToArgb()
     
                Dim obj = oChart.SeriesCollection(1)
                Dim ser As Word.Series = TryCast(obj, Word.Series)
                ser.MarkerStyle = Word.XlMarkerStyle.xlMarkerStyleSquare
                ser.MarkerSize = 4
                dataWorkbook.Application.Quit()
                oword.Visible = True
     
                Dim ochp As Word.Shape = oChart.Parent
                ochp.WrapFormat.Type = WdWrapType.wdWrapTopBottom
     
                opara = odoc.Content.Paragraphs.Add(odoc.Bookmarks.Item("\endofdoc").Range)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Piloter Word depuis Visual Studio 2010
    Par devjp dans le forum Visual Studio
    Réponses: 0
    Dernier message: 09/01/2012, 17h54
  2. Ouvrir Microsoft Word depuis un bouton VB .Net
    Par wiama dans le forum VB.NET
    Réponses: 6
    Dernier message: 28/03/2010, 00h01
  3. Réponses: 1
    Dernier message: 10/06/2009, 15h30
  4. Piloter Excel depuis vb.net
    Par l_achraf dans le forum VB.NET
    Réponses: 7
    Dernier message: 02/04/2009, 20h05
  5. Modifier un graphique Excel depuis Word
    Par hsoulard dans le forum VBA Word
    Réponses: 3
    Dernier message: 21/09/2007, 21h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo