用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧VisualBasic

8、SetXAxisHeadings函数

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 19:47:19
 

Sub SetXAxisHeadings(ByVal oRs As ADODB.Recordset, ByVal strValueCol As String) Dim iCount As Integer Dim iRow, iCol As Integer Dim nMaxRows As Integer Dim oFill As Excel.ChartFillFormat '--- 检查参数是否合法 If (IsNull(oRs) Or IsNull(strValueCol) _ Or oExcelChart.SeriesCollection.Count < 1) Then Err.Raise Number:=1001 + vbObjectError, _ Description:="Invalid recordset or column name" Exit Sub End If On Error GoTo hError '--- 单个数据系列中最大数据个数 nMaxRows = 25 '--- 设置初始值和位置 oRs.MoveFirst iRow = 0: iCol = 1 '--- 循环,将记录集中的数据写入工作表第一列 While (Not oRs.EOF And iRow < nMaxRows) iRow = iRow + 1 '--- 设置单元格的值 oExcelSheet.Cells(iRow, iCol) = CStr(oRs(strValueCol).Value) '--- 下一行 oRs.MoveNext Wend '--- 检查是否确实写入了数据 If (iRow > 0) Then '--- 将这些数据设置为X-轴标签 oExcelChart.SeriesCollection(1).XValues = _ oExcelSheet.Range(oExcelSheet.Cells(1, iCol), _ oExcelSheet.Cells(iRow, iCol)) End If Exit Sub hError: App.LogEvent Err.Description, vbLogEventTypeError Err.Raise Err.Number, Err.Source, Err.DescriptionEnd Sub

   该方法的处理步骤与AddDataSeries()方法相似。标题也是作为记录集的一个列传入,其中的值被加入到工作表中保留的第一个列,然后程序使用Series对象的XValues对象和工作表对象的Range()方法将这些数据加入图表。Range()方法返回的是一个区域,该区域被赋给了Chart对象的XValues对象。


Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

相关文章

PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:19,343.75000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号