1 pièce(s) jointe(s)
[Excel][C#] Création de graphique avec ChartObjects
Bonjour à tous,
je souhaite créer un graphique à l'aide de données récupérer dans Excel. Pour cela j'ai trouvé un exemple mais je me prends une Exception à l'appel d'une des méthode de l'exemple. Voici le code :
Code:
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
|
Excel.Range range5 = sheet.get_Range("A5", "J6");
double[,] array5 = new double[2, 10];
for (int j = 0; j < array5.GetLength(1); j++)
{
double arg = Math.PI / array5.GetLength(1) * j;
array5[0, j] = Math.Sin(arg);
array5[1, j] = Math.Cos(arg);
}
range5.Value2 = array5;
// The following code draws the chart
range5.Select();
Excel.ChartObjects chartobjects = (Excel.ChartObjects)sheet.ChartObjects(Missing.Value);
Excel.ChartObject chartobject = (Excel.ChartObject)chartobjects.Add(10 /*Left*/, 100 /*Top*/, 450 /*Width*/, 250 /*Height*/); //<---- Exception sur cette ligne
Excel._Chart chart = (Excel._Chart)chartobject.Chart;
// Call to chart.ChartWizard() is shown using late binding technique solely for the demonstration purposes
Object[] args7 = new Object[11];
args7[0] = range5; // Source
args7[1] = Excel.XlChartType.xl3DColumn; // Gallery
args7[2] = Missing.Value; // Format
args7[3] = Excel.XlRowCol.xlRows; // PlotBy
args7[4] = 0; // CategoryLabels
args7[5] = 0; // SeriesLabels
args7[6] = true; // HasLegend
args7[7] = "Sample Chart"; // Title
args7[8] = "Sample Category Type"; // CategoryTitle
args7[9] = "Sample Value Type"; // ValueTitle
args7[10] = Missing.Value; // ExtraTitle
chart.GetType().InvokeMember("ChartWizard", BindingFlags.InvokeMethod, null, chart, args7); |
je suis sous VS 2005, j'ai ajouter les reference aux objets COM Excel et OFFICE dans mon projet.
l'exception retournée est en PJ
voilà si quelqu'un a nue idée du pourquoi du coment je le remercie d'avance.
bonne journée
;)