Create Excel chart using C#

J

Jeff Boeker

Hello,

Where can one find the Visual Studio Tools for Office help file? I
downloaded the Visual Tools for Microsoft Office System 2003 and
didn't find the help file. I

Thanks,

Jeff

Sashi said:
I could not find much documentation on step 4 above.
I am trying Workbook.Charts.Add(). Is there any good
documentation or sample C# code for this?

Hi,

I copied this straight out of the Visual Studio Tools for Office help
file:


// ---------
public void CreateChart()
{
Excel.Worksheet thisWorksheet;
thisWorksheet = thisWorkbook.ActiveSheet as Excel.Worksheet;
Excel.ChartObjects charts =
(Excel.ChartObjects)this.thisWorksheet.ChartObjects(Type.Missing);

// Adds a chart at x = 100, y = 300, 500 points wide and 300 tall.
Excel.ChartObject chartObj = charts.Add(100, 300, 500, 300);
Excel.Chart chart = chartObj.Chart;

// Gets the cells that define the bounds of the data to be
charted.
Excel.Range chartRange = this.thisWorksheet.get_Range("A5","D8");
chart.SetSourceData(chartRange,Type.Missing);

chart.ChartType = Excel.XlChartType.xlXYScatter;
Excel.SeriesCollection seriesCollection=
(Excel.SeriesCollection)chart.SeriesCollection(Type.Missing);
Excel.Series series =
seriesCollection.Item(seriesCollection.Count);
}

//----------

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top