8、SetXAxisHeadings函数
[入库:2005年8月18日] [更新:2007年3月25日]
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对象。
本文关键:8、SetXAxisHeadings函数
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)