加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

get chartobjects from VB.net

发布时间:2020-12-16 23:03:49 所属栏目:大数据 来源:网络整理
导读: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.ChartO

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读