Vb.Net中的Excel图表编程 [英] Excel Chart Programming in Vb.Net
问题描述
我遇到了一个关键问题,如下所述:
我正在以编程方式开发一个图表,借助于.Net中的Excel Interop,该图表将保存在Excel工作表中.
但是我不能使用轴标题的下标属性,因此标题的仅一部分显示为带下标,其余的将是普通字体.
即
I am stuck with a critical issue as explained below:
I am developing a chart programmatically that is saved in an Excel Worksheet with the help of Excel Interop in .Net.
But I cannot use the subscript property of the axis title so that only a part of the title is shown as subscripted and rest will be normal font.
ie.
Dim MyChart As Excel.Chart = CType(MyWorksheet.ChartObjects(1), Excel.ChartObject).Chart
Dim MyAxis As Excel.Axis = CType(MyChart.Axes(Excel.XlAxisType.xlValue), Excel.Axis)
MyAxis.AxisTitle.Text = "cmax"
MyAxis.AxisTitle.Characters(2,3).Font.Subscript = True
现在,上面的代码使整个标题被下标,好像将代码编写为一样:
AxisTitle.Characters().Font.Subscript = True
Now the above line makes the whole tittle subscripted as if there is no difference in writing the code as :
AxisTitle.Characters().Font.Subscript = True
Any help will be extremely appreciated
推荐答案
此代码似乎在VBA中有效.
This code seems to work in VBA.
ActiveSheet.ChartObjects("Chart 1").Activate
With ActiveChart.Axes(xlCategory)
.HasTitle = True
With .AxisTitle
.Caption = "Revenue (millions)"
.Font.Name = "bookman"
.Font.Size = 10
.Characters(10, 8).Font.Subscript = True
End With
End With
唯一的区别是标题与文本,.HasTitle必须为true或对象不存在.
The only difference is caption vs. text and .HasTitle must be true or the object doesn''t exist.
这篇关于Vb.Net中的Excel图表编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!