How ASP builds charts with Excel

Source: Internet
Author: User
Tags add array html tags log range
excel| Chart |excel| Chart Now let's take another example of Excel, and we all ask how to create a chart with ASP, and here's the solution

The type of script
First set the script type
<%@ language= "VBSCRIPT"%>

Make the object, and set the object to a ExcelSheet
Create a ExcelSheet object

Dim Myexcelchart
Set Myexcelchart = CreateObject ("Excel.Sheet")

' Show or dont show Excel to user, TRUE or FALSE
Whether to let users see Excel tables, True or False
MyExcelChart.Application.Visible = True

' Populate the Cells
Add Excel Table
MyExcelChart.ActiveSheet.Range ("B2:k2"). Value = Array ("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
MyExcelChart.ActiveSheet.Range ("B3:k3"). Value = Array ("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
MyExcelChart.ActiveSheet.Range ("B4:k4"). Value = Array ("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
MyExcelChart.ActiveSheet.Range ("B5:k5"). Value = Array ("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
MyExcelChart.ActiveSheet.Cells (3,1). Value= "Internet Explorer"
MyExcelChart.ActiveSheet.Cells (4,1). Value= "Netscape"
MyExcelChart.ActiveSheet.Cells (5,1). Value= "Other"

' Select the ' contents ' need to being in the chart
Select the data you want to display in the chart (CHART) in the Excel table
MyExcelChart.ActiveSheet.Range ("B2:k5"). Select

' Add the chart
Load Chart (CHART)
MyExcelChart.Charts.Add
' Format ' chart, set type of chart, shape of the bars, show title, get the "data for" chart, show DataTable, show leg End
Initialize the chart (CHART), set the chart type, the shape of the bar chart, the caption to be displayed, get the data to be plotted, display the datasheet, display the chart
MyExcelChart.activechart.ChartType = 97
MyExcelChart.activechart.BarShape =3
MyExcelChart.activechart.HasTitle = True
MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"
MyExcelChart.activechart.SetSourceData myexcelchart.sheets ("Sheet1"). Range ("A1:k5"), 1
MyExcelChart.activechart.Location 1
MyExcelChart.activechart.HasDataTable = True
MyExcelChart.activechart.DataTable.ShowLegendKey = True

' Save the ' ExcelSheet to Excelface
Save in Excel table
Myexcelchart.saveas "C:\chart.xls"
%>

Now lets complete the HTML tags.
Here is the HTML code

<HTML>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>

This is completes yer ASP page, look below for the complete code of myexcelchart.asp
The following is the complete code for the source program myexcelchart.asp

<%@ language= "VBSCRIPT"%>
<%
Set Myexcelchart = CreateObject ("Excel.Sheet")

MyExcelChart.Application.Visible = True

MyExcelChart.ActiveSheet.Range ("B2:k2"). Value = Array ("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
MyExcelChart.ActiveSheet.Range ("B3:k3"). Value = Array ("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
MyExcelChart.ActiveSheet.Range ("B4:k4"). Value = Array ("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
MyExcelChart.ActiveSheet.Range ("B5:k5"). Value = Array ("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
MyExcelChart.ActiveSheet.Cells (3,1). Value= "Internet Explorer"
MyExcelChart.ActiveSheet.Cells (4,1). Value= "Netscape"
MyExcelChart.ActiveSheet.Cells (5,1). Value= "Other"

MyExcelChart.ActiveSheet.Range ("B2:k5"). Select

MyExcelChart.Charts.Add
MyExcelChart.activechart.ChartType = 97
MyExcelChart.activechart.BarShape =3
MyExcelChart.activechart.HasTitle = True
MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"
MyExcelChart.activechart.SetSourceData myexcelchart.sheets ("Sheet1"). Range ("A1:k5"), 1
MyExcelChart.activechart.Location 1
MyExcelChart.activechart.HasDataTable = True
MyExcelChart.activechart.DataTable.ShowLegendKey = True

Myexcelchart.saveas "C:\chart.xls"

%>
<HTML>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>



Related Article

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.