原程序是ASP的,实现数据导出比较困难,小弟刚学asp.net不久,不知道ASP.NET能不能和以前的ASP兼容且并存在一个系统中,然后用ASP.NET来实现数据导出!!

解决方案 »

  1.   

    整个系统重做吗,这个太麻烦了,因为现在这个系统都是ASP开发的,但是数据导出有困难,希望能用.net来实现!
      

  2.   

    我试了建立.NET架构
    然后新建.aspx的页面(用C#),加入原来的ASP代码,但是高度通不过。
    我刚学。NET 是菜鸟,请大家给点指点!!
      

  3.   

    我这里有一个导出Excel的类,你参考一下.
    using System;
    using System.Data;
    using System.IO;
    using System.Web;
    using DAL;namespace LL.LCommon
    {
    /// <summary>
    /// ToExcel 的摘要说明。
    /// </summary>
    public class ToExcel
    {
    public ToExcel()
    {
    }
    /// <summary>
    /// 导出Excel
    /// </summary>
    /// <param name="ColName"></param>
    /// <param name="Col"></param>
    /// <param name="SqlStr"></param>
    /// <returns>//0,成功。1,没有数据。3,获取DataSet失败。</returns>
    public int GetExcel(string[] ColName,string[] Col,string SqlStr)
    {
    DataAccess MyDA=new DataAccess();
    DataSet MyDS=new DataSet();
    int MyResult=MyDA.GetDataSet(SqlStr,MyDS);
    MyDA.Dispose();
    if(MyResult==0)
    {
    return GetExcel(ColName,Col,MyDS);
    }
    else
    {
    return MyResult;
    }
    } /// <summary>
    /// 导出Excel
    /// </summary>
    /// <param name="ColName"></param>
    /// <param name="Col"></param>
    /// <param name="MyDS"></param>
    /// <returns>//0,成功。1,没有数据。</returns>
    public  int GetExcel(string[] ColName,string[] Col,DataSet MyDS)
    {
    DataTable MyDT=MyDS.Tables[0];
    return GetExcel(ColName,Col,MyDT);
    } /// <summary>
    /// 导出Excel
    /// </summary>
    /// <param name="ColName"></param>
    /// <param name="Col"></param>
    /// <param name="MyDT"></param>
    /// <returns>0,成功。1,没有数据。</returns>
    public int GetExcel(string[] ColName,string[] Col,DataTable MyDT)
    {
    StringWriter MySW=new StringWriter();
    if(ColName.Length!=0)
    {
    for(int i=0;i<ColName.Length;i++)
    {
    MySW.Write(ColName[i]+"\t");
    }
    MySW.WriteLine();
    }
    if(MyDT.Rows.Count==0)
    {
    return 1;
    }
    else
    {
    for(int j=0;j<MyDT.Rows.Count;j++)
    {
    for(int k=0;k<Col.Length;k++)
    {
    MySW.Write(MyDT.Rows[j][Col[k]]+"\t");
    }
    MySW.WriteLine();
    }
    }

    HttpContext.Current.Response.Clear(); 
    HttpContext.Current.Response.Buffer= false; 
    HttpContext.Current.Response.Charset="GB2312"; 
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"); 
    HttpContext.Current.Response.ContentType = "application/ms-excel"; 
    HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312"); 
    HttpContext.Current.Response.Write(MySW); 
    HttpContext.Current.Response.End(); 
    return 0;
    } }
    }