Excel.Sheets sheets = oWB.Worksheets;
Excel.Worksheet thisWorksheet = (Excel.Worksheet)sheets.get_Item(1);
Excel.ChartObjects charts =
(Excel.ChartObjects)thisWorksheet.ChartObjects(Type.Missing);
Excel.ChartObject chartObj = (Excel.ChartObject)charts.Item(1);
Excel.Chart chart = chartObj.Chart;
Excel.Axis a =
(Excel.Axis)chart.Axes(Excel.XlAxisType.xlValue,Excel.XlAxisGroup.xlPrimary);
a.MinimumScale = System.Convert.ToDouble(((Excel.Range)oSheet.Cells[2,
5]).Value2);
"James Tow" wrote:
> Thanks for the response. Unfortunately I am working in C# and the two are
> like Avocados and Kiwi Fruit (since the genetic structure of Apples and
> Oranges are quite close it's not an appropriate comparison). I have made some
> progress thanks to some posts I found in other MS forums. Specifically I have
> the following that will give me the chart object:
>
> Excel.Sheets sheets = oWB.Worksheets;
> Excel.Worksheet thisWorksheet = (Excel.Worksheet)sheets.get_Item(1);
> thisWorksheet = oWB.ActiveSheet as Excel.Worksheet;
> Excel.ChartObjects charts =
> (Excel.ChartObjects)thisWorksheet.ChartObjects(Type.Missing);
> Excel.ChartObject chartObj = (Excel.ChartObject)charts.Item(1);
> Excel.Chart chart = chartObj.Chart;
>
> Now what I am after is to be able to be able to do the following but in C#:
> (Note: the following is from the VBA code when recording a Macro)
>
> ActiveSheet.ChartObjects("Chart 1").Activate
> ActiveChart.Axes(xlValue).Select
> With ActiveChart.Axes(xlValue)
> .MinimumScale = 2000
> .MaximumScaleIsAuto = True
> .MinorUnitIsAuto = True
> .MajorUnitIsAuto = True
> .Crosses = xlAutomatic
> .ReversePlotOrder = False
> .ScaleType = xlLinear
> .DisplayUnit = xlNone
> End With
>
>
> "Tom Ogilvy" wrote:
>
> > a ChartObject on a Sheet has the Chart object
> >
> > In VBA
> >
> > set oSheet = Worksheets(1)
> >
> > msgBox oSheet.ChartObjects(1).Chart.Name
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> > "James Tow" <James Tow@discussions.microsoft.com> wrote in message
> > news:6552A3BA-BA04-4076-943C-30FE1699D4D4@microsoft.com...
> > > I have a Web app that generates Excel documents by calling a stored
> > > procedure,populating a spreadsheet template,that has a chart on the
> > first
> > > sheet. It's all in C#. Here is a brief glimpse of the code;
> > >
> > > oSheet = (Excel.Worksheet)oWB.Worksheets[1];
> > > int iRow=2;
> > > while(myReader.Read())
> > > {
> > > sMELocalID = myReader.GetValue(1).ToString();
> > > for (int k = 0;k < myReader.FieldCount;k++)
> > > {
> > > oSheet.Cells[iRow,k+1] = myReader.GetValue(k).ToString();
> > > }
> > > iRow++;
> > > }
> > > myReader.Close();
> > > myReader=null;
> > >
> > > ***************************
> > >
> > > On oSheet I have a chart called "Chart 2". How do I reference that chart?
> > I
> > > need to change some properties to the axis data and I can't for the life
> > of
> > > me get the darn thing to work! When I debug the app and view the objects,
> > > specifically the oSheet object,I see the Charts property and it lists the
> > > chart count at 0. Any suggestions are most appreciated.
> > >
> > > Thank you so much in advance for any consideration.
> > >
> > > James
> >
> >
http://hanatyan.sakura.ne.jp/dotnet/Excel03.htm