zoukankan      html  css  js  c++  java
  • datagrid gridview 倒出数据为 excel 时,编号问题

            把gridview  中的数据倒出 为 excel时 (编号长时在 excel 中会变成科学计数)


    //倒出按钮  

     
    protected void Btn_ExportClick(object sender, EventArgs e)
        
    {
            
    string style = @"<style> .text { mso-number-format:\@; } </script> "
              
    //主要是这
            Response.ClearContent();
            Response.AddHeader(
    "content-disposition""attachment; filename=MyExcelFile.xls");
            Response.ContentType 
    = "application/excel";

            StringWriter sw 
    = new StringWriter();
            HtmlTextWriter htw 
    = new HtmlTextWriter(sw);

            gvUsers.RenderControl(htw);
            
    // Style is added dynamically
            Response.Write(style); 
            Response.Write(sw.ToString());
            Response.End();
        }


     
    //行绑定事件
     protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
        
    {      

            
    if (e.Row.RowType == DataControlRowType.DataRow)
            
    {
                e.Row.Cells[
    4].Attributes.Add("class""text");  //主要是这
            }

        }



    具体可以看这
    http://gridviewguy.com/ArticleDetails.aspx?articleID=197
  • 相关阅读:
    flutter 和 NTFS
    APIO2020 游记
    CF1336F Journey
    ZJOI2020 游记
    CF568E Longest Increasing Subsequence
    CSP2020 游记
    洛谷 P6217 简单数论题
    CF587F Duff is Mad
    CF526G Spiders Evil Plan
    WC2021 游记
  • 原文地址:https://www.cnblogs.com/gwazy/p/484373.html
Copyright © 2011-2022 走看看