【IT168技术文档】
写这篇文章之前,先提几个问题,希望高手留言指点、讨论:
1、 水晶报表(Crystal Reports)的表头能不能冻结,即:记录多的时候,记录翻页而报表的头部持久显示;如果能怎么实现。
2、 水晶报表在设计的时候表头字段是拖上去的,如果要做一个报表定制工具,这个表头能用程序控制吗?(非vs2005自带的水晶报表)
3、 OWC组建在用vs2005做Web开发的时候为什么添加不到工具栏,而vs2003可以,vs2005的Winform程序也可以。
正是前面提到的问题1和问题2无法解决,现在要把整个系统中的水晶报表换成用Excel实现,Excel实现也存在一些问题,有难度,首先是报表表头的样式的控制,当然这我们可以用宏,但宏是不安全的,所有人都知道,不用宏就只能用VBA语句了,这个对我来说是比较陌生;其次是数据的统计和图表的显示;最后就是用户根据需求自行定制报表,这个灵活性太大,整个模型中数据表就近400张,组织管理细节太多。
先完成了一个小试验,分享一下吧,试验的内容包括:
1、 用简单的VBA语句给Excel中写数据。
2、 将Excel放置在Web页面上来操作。
3、 通过不同框架传值来更新Web页面上的Excel数据内容。
4、 控制输出上下标格式的数据。
5、 更新Excel内容时强制结束前一个Excel进程(同时也会结束用户进程,是本实例的一个bug)。
步骤:
一、新建一个asp.net网站,添加一个纯Html页面Default.htm,在页面上定义两个框架,如下:
二、 在添加一个输入的aspx页面:Input.aspx。在页面上放置一个DropDownList,命名为DDL_Time,和一个Button命名为BN_Query,在cs文件中写下面代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>无标题页</title> </head> <frameset rows ="30,80%"> <!--border="0" framespacing="0" frameborder="1"--> <frame name="Input" marginwidth="0" marginheight="0" src="Input.aspx" scrolling="no"/> <frame name="Output" src="Output.aspx" scrolling="no" /> </frameset> <body> </body> </html>
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 System.Text; public partial class Input : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DDL_Time.Items.Add("20080415"); DDL_Time.Items.Add("20080416"); DDL_Time.SelectedIndex = 0; } } protected void BN_Query_Click(object sender, EventArgs e) { Location("Output.aspx?Time=" + DDL_Time.SelectedItem.ToString()); } /**//// <summary> /// 页面重载 /// </summary> public void Location(string sPath) { StringBuilder sb = new StringBuilder(); sb.Append("<script language=\"javascript\"> \n"); sb.Append("parent.frames['Output'].location.href='" + sPath + "';"); sb.Append("</script>"); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } }