.net 导出excel数据

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 org.in2bits.MyXls;
using Dejun.DataProvider.Table;
using Dejun.DataProvider.Sql2005;
using System.Collections.Generic;

public partial class Admin_ManageProduct_DaoChu1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      

        View_SecKillWinning product = new View_SecKillWinning();
        View_SecKillWinning values = new View_SecKillWinning();
        string qi = "";
        if (!string.IsNullOrEmpty(this.Request.QueryString["qi"]))
        {
            qi = this.Request.QueryString["qi"].ToString();
            product.Qi = Convert.ToInt32(qi);
        }

        string day = "";
        string active = "";
        string a = "";
     
        product.AddConditon(" and addtime>='" + NowMonthTime.GetMonthTime() + "' ");



        List<View_SecKillWinning> m_clientList = TableOperate<View_SecKillWinning>.Select(values, product, 3, " Order by addtime asc,id asc");
        XlsDocument doc = new XlsDocument();
    
        Worksheet sheet = doc.Workbook.Worksheets.Add("Sheet1");
        Worksheet sheet1 = doc.Workbook.Worksheets.Add("Sheet2");
        Worksheet sheet2 = doc.Workbook.Worksheets.Add("Sheet3");

    
        Cell cell = sheet.Cells.Add(1, 1, "0元秒杀中奖列表");
        sheet.Cells.Merge(1, 1, 1, 8);
        cell.HorizontalAlignment = HorizontalAlignments.Centered;
        cell.VerticalAlignment = VerticalAlignments.Centered;

        cell.Font.Height = 16 * 16;//设定字大小(字体大小是以 1/20 point 为单位的)


        sheet.Cells.Add(2, 1, "序列号");
        sheet.Cells.Add(2, 2, "中奖时间");
        sheet.Cells.Add(2, 3, "期数");
        sheet.Cells.Add(2, 4, "姓名");

        sheet.Cells.Add(2, 5, "秒杀资格码");
        sheet.Cells.Add(2, 6, "邮箱");
        sheet.Cells.Add(2, 7, "职业");
        sheet.Cells.Add(2, 8, "电话");
        
        //sheet.Cells.Add(2, 9, "身份证号码");
        sheet.Cells.Add(2, 9, "地址");
        

        //<%#client.Score%> 
        for (int i = 0; i < m_clientList.Count; i++)
        {
            sheet.Cells.Add(i + 3, 1, i);
            sheet.Cells.Add(i + 3, 2, m_clientList[i].AddTime.ToString("yyyy-MM-dd HH:mm:ss"));
            sheet.Cells.Add(i + 3, 3, m_clientList[i].Qi);
            sheet.Cells.Add(i + 3, 4,  m_clientList[i].Name);
            sheet.Cells.Add(i + 3, 5, m_clientList[i].ActivationCode);
            sheet.Cells.Add(i + 3, 6, m_clientList[i].Email);
            sheet.Cells.Add(i + 3, 7, m_clientList[i].Occupation);
            sheet.Cells.Add(i + 3, 8, m_clientList[i].Phone);
            //sheet.Cells.Add(i + 3, 9, m_clientList[i].Shenfz);
            sheet.Cells.Add(i + 3,9, m_clientList[i].Address);


        }




        string fileName = HttpUtility.UrlEncode(day+"O元秒杀中奖列表.xls");//客户端保存的文件名
        //以字符流的形式下载文件
        //OutputStream
        //FileStream fs = new FileStream(filePath, FileMode.Open);
        //Response.OutputStream
        //byte[] bytes = new byte[(int)fs.Length];
        //fs.Read(bytes, 0, bytes.Length);
        //fs.Close();
        Response.ContentType = "application/octet-stream";
        //通知浏览器下载文件而不是打开
        //Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
        Response.AddHeader("Content-Disposition", "attachment;  filename=" + fileName);
        //Response.BinaryWrite(bytes);
        doc.Save(Response.OutputStream);
        Response.Flush();
        Response.End();


    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值