ASP export Graph

   
 


 

 

Home

Board-Forum-Diary

Administrator

ASP

=> ASP?

=> ASP : Connection Object

=> Connect DB access

=> Connect DB Ms Sql Server 7.0

=> ASP and SQL

=> ASP Mysql (ODBC)

=> ASP export Excel

=> ASP export Graph

=> ASP MS-word

=> ASP read data EXCEL

=> ASP read data EXCEL2

Business Manage

Computer Basic

Computer Hardware

Computer Software

Computer Tip

Computer Virus

Contact

Database

Firefox

Gallery

Game

HI5 ME!

Link

Project Demo

System Analysis

Website

Food & Drink

SkyDrive

MS-word

MS-excel

Mobile

Drug

Clock

Car & Motorcycle

Download

 


     
 

ASP ออกรายงานเป็นกราฟในรูปแบบของ GIF ไฟล์

สำหรับการออกรายงานในรูปแบบของ กราฟ ยังคงจะต้องใช้ ความสามารถของ COM ฝั่ง Server ครับ
โดยฝั่ง Server จะต้องทำการติดตั้ง Microsoft Office เพื่อให้โปรแกรมสามารถเรียกใช้งาน Excel.Application

มาดูตัวอย่างกันหน่อยนะครับ

Sample1.asp

<% @ Language="VBScript" %>
<%
Response.Buffer=True
Response.Clear

Dim xlApp,xlBook,xlSheet,objConn,objRS,iRow
Dim objFileCache,bXlsFile,strFileName

iRow = 4
strFileName = "MyChart.xls"

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strConn = strConn & Server.MapPath("Sales00.mdb")
strQuery = "SELECT ProductName,ProductIncome FROM ProductSales"

objConn.Open strConn

objRS.Open strQuery, objConn

If Not objRS.EOF and Not objRS.BOF Then
arrData = objRS.GetRows()
Else
bNoRecords = True
End If

objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing

'-------------------------------- END of DATA Acquisition---------------------

'-------------------------------- BEGIN XLS Generation -----------------------

strFileName = "MyChart.xls"
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

xlApp.Application.Visible = False

xlBook.Sheets.Add
xlBook.ActiveSheet.Name = "Data"

For i = 0 To Ubound(arrData,2)
xlBook.Sheets("Data").Cells(iRow+i,1).Value = arrData(0,i)
xlBook.Sheets("Data").Cells(iRow+i,2).Value = arrData(1,i)
xlBook.Sheets("Data").Cells(iRow+i,2).NumberFormat = "$#,##0.00"
Next

'--- Creating Chart
xlBook.Charts.Add
xlBook.ActiveChart.Name = "Graph"
xlBook.Charts("Graph").SetSourceData (xlBook.Sheets("Data").Range("A4:B9"))

'--- 3DPieExploded (เลือกประเภทของกราฟ)
With xlBook.Charts("Graph")
.ChartType = 70
.PlotBy = 2
.HasTitle = 1
.charttitle.Characters.Text = "Overall Product Sales 2000"
.charttitle.Font.Name = "Tahoma"
.charttitle.Font.FontStyle = "Bold"
.charttitle.Font.Size = 30
.charttitle.Font.ColorIndex = 3
End With

'--- 3DColumns (เลือกประเภทของกราฟ)
'With xlBook.Charts("Graph")
' .ChartType = 54
' .PlotBy = 1
' .HasAxis(1) = 0
' .HasTitle = 1
' .charttitle.Characters.Text = "Overall Product Sales 2000"
' .charttitle.Font.Name = "Tahoma"
' .charttitle.Font.FontStyle = "Bold"
' .charttitle.Font.Size = 30
' .charttitle.Font.ColorIndex = 3
'End With

Set fso = CreateObject("Scripting.FileSystemObject")
strTempName = fso.GetTempName
strFileName= Replace(strTempName,".tmp",".htm")

xlBook.Charts("Graph").SaveAs Server.MapPath(strFileName),44

xlApp.Application.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

strTempDir =Replace(strFileName,".htm","_files")

If (fso.FileExists(Server.MapPath(strTempDir & "image001.gif"))) Then
Set MyFile = fso.GetFile(Server.MapPath(strTempDir & "image001.gif"))
strGifName = Replace(strTempDir, "_files",".gif")
MyFile.Move Server.MapPath(strGifName)

strDelFile=Replace(strTempDir, "_files",".htm")
Set MyDelFile = fso.GetFile(Server.MapPath(strDelFile))
MyDelFile.Delete
fso.DeleteFolder (Server.MapPath(strTempDir))
End If

Set MyFile = Nothing
Set MyDelFile = Nothing
Set fso = Nothing
%>









 
 

Total, there have been 124923 visitors (304841 hits) on this page!