1、首先下载owc11:owc11
2、引用OWC:打开"解决方案资源管理器"面板,鼠标右键单击"引用",选择"添加引用"菜单,在弹出的"添加引用"对话框中单击"COM"卡片,找到"Microsoft Office Web Components 10.0(office 2003是11.0)",单击"选择"和"确定"按钮,OWC就被添加到了引用中。
3、建立一个pic.aspx文件,aspx代码如下:
<script language="javascript" type="text/javascript" src="/js/Calendar30.js"></script>
选择开始日期和结束日期。如果时间范围超过365则显示年表,如果时间范围超过30则显示月份表,如果超过1则显示日期表,否则显示小时表。<br />
开始日期:<input id="s" type="text" value="<%= Request.QueryString["s"]%>" onclick="fillDay(this)" >结束日期:<input id="e" value="<%= Request.QueryString["e"]%>" type="text" onclick="fillDay(this)" /><input type="button" value="查看" onclick="location.href='?s='+$F('s')+'&e='+$F('e')" /><br />
<asp:placeholder id="ChartHolder" runat="server"></asp:placeholder>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Owc11;
public partial class pic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && Request.QueryString["s"] != null && Request.QueryString["e"] != null)
{
string file;
DateTime s = DateTime.Parse(Request.QueryString["s"]);
DateTime et = DateTime.Parse(Request.QueryString["e"]);
string x = "";
string y = "";
string danwei = "时";
string sql = "";
int r = ((TimeSpan)(et - s)).Days;
//Response.Write(r);
//Response.Write("<br />");
if (r >= 365)
{
sql = "select datepart(yyyy,regtime) d,count(*) c from t_user where regtime between '{0}' and '{1}' group by datepart(yyyy,regtime) order by d";
danwei = "年";
}
else if (r >= 30)
{