3.菜单project,选择菜单项references,然后请把microsoft active server pages ojbect library、microsoft excel 9.0 object library、com+ services type library选上。
注意:在nt4/win98上没有com+ service type library这个东东,应该选microsoft transaction server type library
4.编辑pie.cls,代码如下:
'-------------------------------------------------------------------------------
dim xl
dim m_chartname
dim m_chartdata()
dim m_charttype
dim m_filename
public errmsg
public founderr
dim icount
type m_value
label as string
value as double
end type
dim tvalue as m_value
public property let charttype(charttype)
m_charttype = charttype
end property
public property get charttype()
charttype = m_charttype
end property
public property let chartname(chartname)
m_chartname = chartname
end property
public property get chartname()
chartname = m_chartname
end property
public property let filename(fname)
m_filename = fname
end property
public property get filename()
filename = m_filename
end property
public sub addvalue(label, value)
icount = icount + 1
redim preserve m_chartdata(icount)
tvalue.label = label
tvalue.value = value
m_chartdata(icount) = tvalue
end sub
public sub savechart()
on error resume next
dim isheet
dim i
set xl = new excel.application
xl.application.workbooks.add
xl.workbooks(1).worksheets("sheet1").activate
if err.number <> 0 then
founderr = true
errmsg = err.description
err.clear
else
xl.workbooks(1).worksheets("sheet1").cells("2,1").value = m_chartname
for i = 1 to icount
xl.worksheets("sheet1").cells(1, i + 1).value = m_chartdata(i).label
xl.worksheets("sheet1").cells(2, i + 1).value = m_chartdata(i).value
next
xl.charts.add
xl.activechart.charttype = m_charttype
xl.activechart.setsourcedata xl.sheets("sheet1").range("a1:" & chr((icount mod 26) + asc("a")) & "2"), 1
xl.activechart.location 2, "sheet1"
with xl.activechart
.hastitle = true
.charttitle.characters.text = m_chartname
end with
xl.activechart.applydatalabels 2, false, _
true, false
with xl.selection.border
.weight = 2
.linestyle = 0
end with
xl.activechart.plotarea.select
with xl.selection.border
.weight = xlhairline
.linestyle = xlnone
end with
xl.selection.interior.colorindex = xlnone
xl.activewindow.visible = false
xl.displayalerts = false
xl.activechart.export m_filename, filtername:="gif"
xl.workbooks.close
if err.number <> 0 then
founderr = true
errmsg = errmsg
err.clear
end if
end if
set xl = nothing
end sub
private sub class_initialize()
icount = 0
founderr = false
errmsg = ""
m_charttype = -4102 'xl3dpie
'54 '柱状图
end sub
'-------------------------------------------------------------------------------