打印本文 打印本文 关闭窗口 关闭窗口
8、SetXAxisHeadings函数
作者:武汉SEO闵涛  文章来源:敏韬网  点击数767  更新时间:2009/4/23 18:58:48  文章录入:mintao  责任编辑:mintao
 

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.Description End Sub

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

打印本文 打印本文 关闭窗口 关闭窗口