using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Text;

public partial class ckgl_ck_ckqd : System.Web.UI.Page
{
    private static BLLV_Order bllv_order = new BLLV_Order();
    private static BLLOutbound bll_outbound = new BLLOutbound();
    private static BLLOrderDetial bll_orderdetial = new BLLOrderDetial();
    private static BLLV_OutboundDetial bllv_outbounddetial = new BLLV_OutboundDetial();
    private static BLLV_OutboundDetial_Count_Ext bll_outbounddetial_ext = new BLLV_OutboundDetial_Count_Ext();
    protected static BLLStorage bllstorage = new BLLStorage();
    protected BLLSpace bllspace = new BLLSpace();
    List<StorageModel> storagemodellist = bllstorage.SelectAll();
    private static BLLOrder bllorder = new BLLOrder();
    private static int PageSize = 10000;
    private static string Order_IDs = "";
    private static string Outbound_ID = "";
    private static V_OutboundDetialModel v_obdm = new V_OutboundDetialModel();
    private static BLLOperLog blloperlog = new BLLOperLog();

//导出Excel文件
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        Dictionary<string, string> dicspace = new Dictionary<string, string>();
        foreach (var item in storagemodellist)
        {
            SpaceModel sm = new SpaceModel();
            sm.Storage_ID = item.Storage_ID;
            List<SpaceModel> spacelist = bllspace.Select(sm, "1");
            foreach (var space in spacelist)
            {
                dicspace.Add(item.Storage_ID + space.Space_ID, space.Name);
            }
        }
        try
        {
            V_OutboundDetial_Count_ExtModel outbounddetial_ext_model = new V_OutboundDetial_Count_ExtModel();
            outbounddetial_ext_model.Outbound_ID = Outbound_ID;
            outbounddetial_ext_model.OutType = "0";
            List<V_OutboundDetial_Count_ExtModel> count_ext_models = bll_outbounddetial_ext.Select(outbounddetial_ext_model, "1");
            DataTable dt = new DataTable();
            DataColumn[] dc ={
                           new DataColumn("学习资料编号"),
                           new DataColumn("教学资料名称"),
                           new DataColumn("订购类型"),
                           new DataColumn("数量"),
                           new DataColumn("单价(元)"),
                           new DataColumn("库位"),
                           new DataColumn("仓位")
                       };
            dt.Columns.AddRange(dc);
            DataRow drHead = dt.NewRow();
            drHead["学习资料编号"] = "学习资料编号";
            drHead["教学资料名称"] = "教学资料名称";
            drHead["订购类型"] = "订购类型";
            drHead["数量"] = "数量";
            drHead["单价(元)"] = "单价(元)";
            drHead["库位"] = "库位";
            drHead["仓位"] = "仓位";
            dt.Rows.Add(drHead);
            //导入内容
            foreach (var model in count_ext_models)
            {
                DataRow dr = dt.NewRow();
                dr["学习资料编号"] = model.TMID;
                dr["教学资料名称"] = model.TMName;
                dr["订购类型"] = model.OrderName;
                dr["数量"] = model.SumCount;
                dr["单价(元)"] = model.Price;
                dr["库位"] = model.StorName;
                dr["仓位"] = dicspace[model.Storage_ID + model.Space_ID];
                dt.Rows.Add(dr);
            }
            ExportByWeb(dt, "出库清单.xls");
            //ExportExcel1.FileName = "出库清单.xls";
            //ExportExcel1.ExportToExcel(dt);
        }
        catch (Exception ex)
        {
            string strmessage = @"alert('" + ex.Message + "');";
            ClientScript.RegisterStartupScript(this.GetType(), "", strmessage, true);
        }
    }
 
    public static void ExportByWeb(DataTable dtSource, string strFileName)
    {
        try
        {
            HttpContext curContext = HttpContext.Current;

// 设置编码和附件格式   
            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.ContentEncoding = Encoding.UTF8;
            curContext.Response.Charset = "";
            curContext.Response.AppendHeader("Content-Disposition",
                "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8));

curContext.Response.BinaryWrite(Cau_TeachOrderLibrary.Common.RenderToExcel(dtSource).GetBuffer());
            curContext.Response.End();
        }
        catch (Exception ee)
        {
            throw new ApplicationException("导出过程出错!" + ee.Message);

}

}
}

Excel导出cs文件的更多相关文章

  1. thinkphp3.2.3 excel导出,下载文件,包含图片

    关于导出后出错的问题 https://segmentfault.com/q/1010000005330214 https://blog.csdn.net/ohmygirl/article/detail ...

  2. Excel导出插件

    前言 一个游戏通常需要10多个Excel表格或者更多来配置,一般会通过导出csv格式读取配置. 本文提供导出Excel直接生成c#文件,对应数据直接生成结构体和数组,方便开发排错和简化重复写每个表格的 ...

  3. Excel导出插件-VSTO

    前言 一个游戏通常需要10多个Excel表格或者更多来配置,一般会通过导出csv格式读取配置. 本文提供导出Excel直接生成c#文件,对应数据直接生成结构体和数组,方便开发排错和简化重复写每个表格的 ...

  4. asp.net教程:GridView导出到Excel或Word文件

    asp.net教程:GridView导出到Excel或Word文件</ br> 在项目中我们经常会遇到要求将一些数据导出成Excel或者Word表格的情况,比如中国移动(我是中国移动用户) ...

  5. asp.net(C#) Excel导出类 导出.xls文件

    ---恢复内容开始--- using Microsoft.Office.Interop.Excel; 针对office 2003需添加引用Microsoft   Excel   11.0   Obje ...

  6. (转载)DBGridEh导出Excel等格式文件

    DBGridEh导出Excel等格式文件 uses DBGridEhImpExp; {--------------------------------------------------------- ...

  7. Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类

    Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类 ============================== ©Copyright 蕃薯耀 20 ...

  8. Laravel Excel 实现 Excel-CSV 文件导入导出功能

    Laravel Excel 是一款基于 PHPExcel 开发的Laravel框架专用的 Excel/CSV 文件导入导出功能的扩展包,用起来的非常方便. 它的 Github 地址是:https:// ...

  9. C# Aspose.Cells导出xlsx格式Excel,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”

    报错信息: 最近打开下载的 Excel,会报如下错误.(xls 格式不受影响) 解决方案: 下载代码(红色为新添代码) public void download() { string fileName ...

随机推荐

  1. Codeforces 474D Flowers

    http://codeforces.com/problemset/problem/474/D 思路:F[i]=F[i-1]+(i>=K)F[i-k] #include<cstdio> ...

  2. Qt5+VS2013兼容XP方法

    用Qt5+VS2013编译程序默认配置会在XP运行时报"不是有效的Win32程序"工作需要必须要XP运行 pro文件中加一句: 复制代码 QMAKE_LFLAGS_WINDOWS ...

  3. PowerShell3.0中,所有的命令

    Get-Command * >> cmd.txt CommandType Name ModuleName ----------- ---- ---------- Alias % -> ...

  4. Java获取当前日期的前一个月,前一天的时间

    Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -); //得到前一天 calendar.add(Cal ...

  5. 2015第14周五Tomcat版本

    首先看tomcat官方文档,列出的不同版本的主要差别: Servlet Spec JSP Spec EL Spec WebSocket Spec Apache Tomcat version Actua ...

  6. Textarea - 百度富文本编辑器插件UEditor

    UEditor各种实例演示 Ueditor 是百度推出的一款开源在线 HTML 编辑器. 主要特点: 轻量级:代码精简,加载迅速. 定制化:全新的分层理念,满足多元化的需求.采用三层架构:1. 核心层 ...

  7. Zoj3332-Strange Country II(有向竞赛图)

    You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 t ...

  8. Openstack no valid hot

    错误: 创建实例 "ce" 失败: 请稍后再试 [错误: No valid host was found. ].

  9. Android应用开发学习之状态栏通知

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 状态栏通知涉及到两个类,一是Notification,它代表一个通知:另一个是NotificationManager ...

  10. 《Java程序员面试笔试宝典》之 什么是AOP

    AOP(Aspect-Oriented Programming,面向切面编程)是对面向对象开发的一种补充,它允许开发人员在不改变原来模型的基础上动态地修改模型从而满足新的需求.例如,在不改变原来业务逻 ...