ASP与电子表格EXCEL的交互操作

excel|电子表格|交互

Here we go again with another sample for Excel, this time we will be using ASP to create a chart. You all
asked me for it, now here is the solution. Thanks again for all your nice comments :)

First we set the type of script

<%@ LANGUAGE="VBSCRIPT" %>

Make the object, and set the object to an Excelsheet

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

Now lets write the rest of the script, see the comments

' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True

' populate the cells
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 that need to be in the chart
MyExcelChart.ActiveSheet.Range("b2:k5").Select

' Add the chart
MyExcelChart.Charts.Add
' Format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show
datatable, show legend
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 the excelsheet to excelface
MyExcelChart.SaveAs "c:\chart.xls"
%>

Now lets complete the HTML tags.

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

This completes yer ASP page, look below for the complete code of myexcelchart.asp

<%@ LANGUAGE="VBSCRIPT" %>
<%
' Create Object
Set MyExcelChart = CreateObject("Excel.Sheet")

' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True

' populate the cells
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 that need to be in the chart
MyExcelChart.ActiveSheet.Range("b2:k5").Select

' Add the chart
MyExcelChart.Charts.Add
' Format the chart, set type of chart, shape of the bars, show title, get the data

时间: 2024-11-05 18:32:20

ASP与电子表格EXCEL的交互操作的相关文章

ASP.NET之Excel下载模板、导入、导出操作_实用技巧

本文介绍了ASP.NET下Excel下载模板.导入.导出操作,供大家参考,具体内容如下 1.下载模板功能 protected void btnDownload_Click(object sender, EventArgs e) { var path = Server.MapPath(("upfiles\\") + "test.xlt"); //upfiles-文件夹 test.xlt-文件 var name = "test.xlt"; try {

asp.net读取excel文件的三种方法示例

 这篇文章主要介绍了asp.net读取excel文件的三种方法示例,包括采用OleDB读取Excel文件.引用的com组件读取Excel文件.用文件流读取,需要的朋友可以参考下 方法一:采用OleDB读取Excel文件   把Excel文件当做一个数据源来进行数据的读取操作,实例如下:  代码如下: public DataSet ExcelToDS(string Path)    {    string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;&q

asp.net导出excel的简单方法

 这篇文章主要介绍了asp.net导出excel的简单方法实例,需要的朋友可以参考下 excel的操作,最常用的就是导出和导入,废话不多说上代码.   本例使用NPOI实现的,不喜勿喷哈....    代码如下: /// <summary>         /// 导出Excel         /// </summary>         /// <param name="stime"></param>         /// <

asp.net导出Excel类库代码分享

 这篇文章主要介绍了asp.net导出Excel类库代码,有需要的朋友可以参考一下    代码如下: using System; using System.Collections.Generic; using System.Reflection; using System.Web; using Excel = Microsoft.Office.Interop.Excel;   /// <summary> ///ExcelClass 的摘要说明 /// </summary> publ

问题: asp.net 读取excel 模版 填充数据 另存为

问题描述 如题:用asp.net读取excel模版在填充数据然后另存为html,怎么作,最好有封装好的类, 解决方案 解决方案二:没做过.做个标记,帮顶下.解决方案三:不用封装类,就像操作Access数据库一样,只不过连接字符串有点不一样,如下:Provider=Microsoft.Jet.OleDb.4.0;DataSource="+Excel路径+";ExtendedProperties=Excel8.0;";解决方案四:唉,自己顶一下,希望高手出现.解决方案五:唉,自己

asp.net导出EXCEL的功能代码_实用技巧

复制代码 代码如下: //由gridviw导出为Excel public static void ToExcel(System.Web.UI.Control ctl) { HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls"); HttpContext.Current.Response.Charset = "UTF-8

asp.net中EXCEL数据导入到数据库的方法_实用技巧

本文实例讲述了asp.net中EXCEL数据导入到数据库的方法.分享给大家供大家参考.具体分析如下: excel是办公中非常常用的一个办公表格了,但我们在开发中通常会需要直接把excel数据快速导入到数据库中了,这里整理了一个asp.net中EXCEL数据导入到数据库的例子供各位参考学习. 注意:EXCEL中的第一行不能导入.下面是源码:IntoExcel.aspx: 复制代码 代码如下: <%@ Page  AutoEventWireup="true" CodeFile=&qu

针对Excel表格文件操作的编程实现

简介 通过本文及配套示例源码你可以更加灵活的控制Excel表格文件,其中包括创建新Excel文件.写入表格数据.读取表格数据(包括对原建Excel文件自已手工添加的行.列数据的准确读取),删除已有Excel表格,对表格中指定行.列.单元格进行查询.插入.替换等操作,同时还可以将生成的Excel文件转换为按指定分隔符分隔的其它文本格式的文件.下面是把此方法用VC6编写的示例程序运行效果: 基本思路 基础实现方法同上篇文章<直接通过ODBC读.写Excel表格文件>相同,都是通过ODBC来把Exc

ASP.NETR把Excel导入SQL数据库的自定义类

ASP.NETR把Excel导入SQL数据库的自定义类 以下是引用片段:public class SaveToSql {   public string strNewCodeId = string.Empty;   public string strNewCode = string.Empty;   public string strNewDes = string.Empty;   public string strOldCodeId = string.Empty;   public strin