zoukankan      html  css  js  c++  java
  • C# 导出 excel 模板

    <asp:Button ID="Button1" runat="server" Text="导出PWHT模板" OnClick="btnExport_PWHT_Click" >
    </asp:Button>

    protected void btnExport_PWHT_Click(object sender, EventArgs e)
    {

    string path = Server.MapPath("../z_imes_weldlist/导入热处理报告号模板.xlsx");
    FileInfo fi = new FileInfo(path);//excelFile为文件在服务器上的地址
    if (File.Exists(path))
    {
    Response.Clear();
    Response.Buffer = true; //设置<span style="color: rgb(51, 51, 51); line-height: 24px; white-space: pre-wrap;">输出页面是否被缓冲</span>
    Response.Charset = "GB2312"; //设置了类型为中文防止乱码的出现
    Response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", HttpUtility.UrlEncode("导入热处理报告号模板.xls"))); //定义输出文件和文件名
    Response.AppendHeader("Content-Length", fi.Length.ToString());
    Response.ContentEncoding = Encoding.Default;
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
    Response.WriteFile(fi.FullName);
    Response.Flush();
    Response.End();
    }
    else
    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('此模板不存在!');</script>", false);
    }

    源地址:https://blog.csdn.net/qq_34496400/article/details/51353267

  • 相关阅读:
    JVM基础和调优(一)
    Jtree(节点的渲染+资源管理器)(2)
    Jtree (节点的渲染+资源管理器)
    jtree(选择框)
    java进阶计划
    SQL优化
    spring 事务管理
    Spring事务配置的五种方式(转)
    spring与数据库之间的配置
    struct2(六) 为表单添加验证
  • 原文地址:https://www.cnblogs.com/codejimmygao/p/14857878.html
Copyright © 2011-2022 走看看