How to write a report in Excel in ASP

Source: Internet
Author: User
Excel Line chart

<%
Option Explicit


' Page-level objects
'--------------------
Dim M_CN ' linked object
Dim m_rs ' Recordset object
Dim m_cspace ' OWC. ChartSpace Object
Dim m_fso ' File system object
Dim m_objbinaryfile ' binary file stream object

Dim m_syear ' year to query

Dim sSQL ' executed SQL statement
Dim C ' OWC constant object
Dim CHT ' Chart temp reference variable
Temporary reference variable for Dim ax ' axis
Dim fnt ' owcfont temporary reference variable for font
Dim sfullfilename ' output gif file's temporary reference path

' Get the query year by default of 2002
M_syear = Request.QueryString ("year")
If Len (m_syear) = 0 Then m_syear = "2002"

' Create an ADO link and Recordset object
Set m_cn = Server.CreateObject ("ADODB. Connection ")
Set m_rs = Server.CreateObject ("ADODB. Recordset ")

' Link to an Access database, using the client's cursor engine to open the recordset
M_cn. Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (".") & "\data.mdb"
sSQL = "Select Month ([OrderDate]) as [Month], Invoices.salesperson," & _
"Sum (Invoices.extendedprice) as Sales from Invoices" & _
"WHERE invoices.orderdate between #1/1/" & M_syear & "# and #12/31/" & M_syear & "#" & _
"GROUP by Month ([OrderDate]), Invoices.salesperson"
M_rs. CursorLocation = 3 ' adUseClient
M_rs. Open sSQL, M_CN, 3 ' adOpenStatic

' Add a chart with a legend for the cluster column
Set m_cspace = Server. CreateObject ("OWC.") Chart ")
Set M_cspace. DataSource = M_rs
Set cht = M_cspace. Charts.add ()
Set c = M_cspace. Constants

Cht. HasLegend = True

Cht. Type =c.chcharttypelinemarkers
' Set the data source for the chart, add the salesperson to the name of the sequence, add the sales month to the category group, and the sales amount as the values in the chart


Cht. SetData c.chdimseriesnames, 0, "Salesperson"
Cht. SetData c.chdimcategories, 0, "Month"
Cht. SetData c.chdimvalues, 0, "Sales"


Cht. SeriesCollection (4). Interior.Color = "Blue" Changes the color of the fourth line to blue
Cht.seriescollection (4). Line.color = "Blue"


' Add a chart title and format the title
Cht. HasTitle = True
Cht. Title.caption = m_syear & "Sales Amount"
Set fnt = Cht. Title.font
Fnt. Name = "Song Body"
Fnt. Size = 10
Fnt. Bold = True

' Add a caption to the category axis and format the title
Set ax = cht. Axes (C.chaxispositionbottom)
Ax. HasTitle = True
Ax. Title.caption = "Month"
Set fnt = ax. Title.font
Fnt. Name = "Song Body"
Fnt. Size = 8
Fnt. Bold = True

' Add a caption to the value axis and format the title
Set ax = cht. Axes (C.chaxispositionleft)
Ax. NumberFormat = "Currency"
Ax. HasTitle = True
Ax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.