Delphi 6 – 从delphi应用程序创buildExcel图表 – 数据和图表在同一页面上

我需要从一个delphi程序在excel页面创build一个excel图表。

在达到线路时,我收到“成员未find”错误。

ch1.Chart.SeriesCollection.Item[0].Values := Sheets.Item['Delphi Data'].Range['E5:E15']; 

你能帮我解决吗?

下面给出的是使用的代码。

 procedure TForm1.ChartData; var ARange,Sheets,ch1 : Variant; SSeries : Series; num : integer; ChartAxis : Axis; lcid : Cardinal; begin ch1 := XLApp.ActiveWorkBook.Sheets[1].ChartObjects.Add ( 500,100,400,200 ); // creates a new chart in the specified Sheets := XLApp.Sheets; ch1.Chart.ChartWizard ( Sheets.Item['Delphi Data'].Range['D5:D15'], // 1 Source xlBarStacked, // 2 The chart type. 8, // 3 Format 2, // 4 PlotBy 8, // 5 CategoryLabels 3, // 6 SeriesLabels True, // 7 HasLegend - 'true' to include a legend. 'Sijos Report', // 8 Title - The Chart control title text. 'Y Legend', // 9 CategoryTitle - The category axis title text. 'X Legend', // 10 ValueTitle - The value axis title text 2 // 11 ExtraTitle - The series axis title for 3-D charts or the second value axis title for 2-D charts. ); ch1.Chart.SetSourceData(Sheets.Item['Delphi Data'].Range['D5:D15'],xlColumns); ch1.Chart.SeriesCollection.Item[0].Values := Sheets.Item['Delphi Data'].Range['E5:E15']; ch1.Chart.SeriesCollection.Item[0].XValues := Sheets.Item['Delphi Data'].Range['F5:F15']; End; 

我认为你需要ch1.Chart.SeriesCollection(1)而不是ch1.Chart.SeriesCollection.Item[0]因为Excel使用基于1的索引。

我也无法得到你的代码,在访问该系列对象的时候,使用延迟绑定的COM工作。 但是,如果你切换到使用早期绑定的COM,那么它是好的。 例如,您需要将Excel2000添加到您的使用条款中。

 var S: Series; .... S := IUnknown(ch1.Chart.SeriesCollection(1)) as Series; S.Values := Sheets.Item['Delphi Data'].Range['E5:E15']; S.XValues := Sheets.Item['Delphi Data'].Range['F5:F15']; 

如果我是你,我会把整个代码切换到早期的界限。

我认为你的代码是基于Charlie Calvert的这个Delphi 3的例子 。 我无法让我的Delphi 6工作。也许delphi改变了。 也许Excel改变了。 无论如何,为我工作的东西就是改用早期的COM。