get chartobjects from VB.net

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

http://zhidao.baidu.com/question/125367345

http://www.pcreview.co.uk/forums/thread-985736.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值