excel|資料|圖表 在ASP中調用Excel畫資料圖表,優勢有很多,最突出的是可以輸出多種形式的圖形(總共有72種)。以下是我寫的一個通用ASP方法調用Excel畫資料圖表。
<%
'將資料圖形化輸出
'dataArray二維數組
'virtualFilePath輸出影像檔名(虛擬路徑)
'nType顯示類型
Dim initType
Sub ExportPicture(dataArray,virtualFilePath,nType)
Dim excelapp ' As New excel.Application
Dim excelwbk ' As excel.Workbook
Dim excelcht ' As excel.Chart
Dim excelsht 'As excel.Worksheet
Dim idx,idy,ftype,usedData,totalcount,count:count = 1
On Error Resume Next
Set excelapp = Server.CreateObject("Excel.Application")
Set excelwbk = excelapp.Workbooks.Add()
Set excelcht = excelwbk.Charts.Add()
Set excelsht = excelwbk.Worksheets.Add()
If UCase(Right(virtualFilePath,4)) = ".JPG" Or UCase(Right(virtualFilePath,4)) = ".JPEG" Then
ftype = "jpg"
Else
ftype = "gif"
End If
initType = nType
For idx=LBound(dataArray,1) To UBound(dataArray,1)
For idy=LBound(dataArray,2) To UBound(dataArray,2)
excelsht.Cells(idx+1,idy+1) = dataArray(idx,idy)
Next
Next
Set usedData = excelsht.usedRange
excelcht.SeriesCollection.Add usedData
excelcht.HasLegend = True
excelcht.HasTitle = True
'excelcht.ChartTitle.Caption = "部門員工分布圖"
excelcht.ApplyCustomType nType
excelcht.Export Server.Mappath(virtualFilePath), ftype
excelsht.Close False
excelwbk.Close False
Set usedData = Nothing
Set excelcht = Nothing
Set excelwbk = Nothing
Set excelapp = Nothing
End Sub
%>
<Select name="sel" Onchange="changePict()">
<Option value="51">二維直條圖</Option><!--xlColumnClustered
<Option value="52">xlColumnStacked</Option>
<Option value="53">xlColumnStacked100</Option>-->
<Option value="54">三維柱狀圖</Option><!--xl3DColumnClustered
<Option value="55">xl3DColumnStacked</Option>
<Option value="56">xl3DColumnStacked100</Option>-->
<Option value="57">二維橫條圖</Option><!--xlBarClustered
<Option value="58">xlBarStacked</Option>
<Option value="59">xlBarStacked100</Option>-->
<Option value="60">三維條狀圖</Option><!--xl3DBarClustered
<Option value="61">xl3DBarStacked</Option>
<Option value="62">xl3DBarStacked100</Option>-->
<Option value="63">折線圖</Option><!--xlLineStacked
<Option value="64">xlLineStacked100</Option>
<Option value="65">xlLineMarkers</Option>
<Option value="66">xlLineMarkersStacked</Option>
<Option value="67">xlLineMarkersStacked100</Option>
<Option value="68">xlPieOfPie</Option>
<Option value="69">xlPieExploded</Option>
<Option value="70">xl3DPieExploded</Option>
<Option value="71">xlBarOfPie</Option>-->
<Option value="72">曲線圖</Option><!--xlXYScatterSmooth
<Option value="73">xlXYScatterSmoothNoMarkers</Option>
<Option value="74">xlXYScatterLines</Option>
<Option value="75">xlXYScatterLinesNoMarkers</Option>-->
<Option value="76">折線面積圖</Option><!--xlAreaStacked
<Option value="77">xlAreaStacked100</Option>
<Option value="78">xl3DAreaStacked</Option>
<Option value="79">xl3DAreaStacked100</Option>
<Option value="80">xlDoughnutExploded</Option>
<Option value="81">xlRadarMarkers</Option>
<Option value="82">xlRadarFilled</Option>
<Option value="83">xlSurface</Option>
<Option value="84">xlSurfaceWireframe</Option>
<Option value="85">xlSurfaceTopView</Option>
<Option value="86">xlSurfaceTopViewWireframe</Option>
<Option value="15">xlBubble</Option>
<Option value="87">xlBubble3DEffect</Option>
<Option value="88">xlStockHLC</Option>
<Option value="89">xlStockOHLC</Option>
<Option value="90">xlStockVHLC</Option>
<Option value="91">xlStockVOHLC<