国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
asp.net導(dǎo)出excel

下面這種方法只能導(dǎo)出頁面的Html至Excel:

 1     public static void GridExportExcel(ref System.Web.UI.WebControls.GridView dg, string fileName)
 2     {
 3         System.Web.HttpContext.Current.Response.Clear();
 4         System.Web.HttpContext.Current.Response.Buffer = true;
 5         System.Web.HttpContext.Current.Response.Charset = "GB2312"//設(shè)置了類型為中文防止亂碼的出現(xiàn) 
 6         System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition""attachment;filename=" + fileName + ".xls"); //定義輸出文件和文件名 
 7         System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//設(shè)置輸出流為簡體中文 
 8         System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";//設(shè)置輸出文件類型為excel文件。 
 9         dg.Page.EnableViewState = false;
10         System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN"true);
11         System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
12         System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
13         dg.RenderControl(oHtmlTextWriter);
14         System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString());
15         System.Web.HttpContext.Current.Response.End();
16     }

當(dāng)要從DataSet導(dǎo)出至Excel,則用如下方法:
  1
    protected void btn_out_Click(object sender, EventArgs e)
  2
    
{
  3
        DataSet ds;
  4
        
if ((bool)ViewState["PageIndexChange"== false)
  5
        
{
  6
            Response.Write(
"<script>alert('對不起,沒有查詢到任何記錄,不能導(dǎo)出數(shù)據(jù)')</script>");
  7
            
return;
  8
        }

  9
        
if ((int)Session["userTeam"> 0)
 10
        
{
 11
            
if (ViewState["toolTip"].ToString().CompareTo("部門"== 0)
 12
            
{
 13
                ds 
= rd.GetDeptAttenInfo((string)Session["enterId"], (string)ViewState["strValue"],
 14
            (DateTime)ViewState[
"FromTime"], (DateTime)ViewState["ToTime"], (int)ViewState["ShiftResult"], (int)ViewState["DeptChk"], (int)ViewState["AdminChk"]);
 15
            }

 16
            
else
 17
            
{
 18
                ds 
= rd.GetUserAttenInfo(int.Parse(ViewState["strValue"].ToString()),
 19
            (DateTime)ViewState[
"FromTime"], (DateTime)ViewState["ToTime"], (int)ViewState["ShiftResult"], (int)ViewState["DeptChk"], (int)ViewState["AdminChk"]);
 20
            }

 21
        }

 22
        
else
 23
        
{
 24
            ds 
= rd.GetUserAttenInfo(int.Parse(ViewState["strValue"].ToString()),
 25
            (DateTime)ViewState[
"FromTime"], (DateTime)ViewState["ToTime"], (int)ViewState["ShiftResult"], (int)ViewState["DeptChk"], (int)ViewState["AdminChk"]);
 26
        }

 27
        CreateExcel(ds, 
"1""outExcel");
 28
        
//if (this.gvUser.Rows[0].Cells[0].Text == "" || this.gvUser.Rows[0].Cells[0].Text == "沒有查到數(shù)據(jù)")
 29
        
//{
 30
        
//    Response.Write("<script>alert('對不起,沒有查詢到任何記錄,不能導(dǎo)出數(shù)據(jù)')</script>");
 31

 32
        
//}
 33
        
//else
 34
        
//{
 35
        
//    GridExportExcel(ref this.gvUser, "刷卡記錄");
 36
        
//}
 37
    }

 38
    
public void CreateExcel(DataSet ds, string typeid, string FileName)
 39
    
{
 40
        HttpResponse resp;
 41
        resp 
= Page.Response;
 42
        resp.ContentEncoding 
= System.Text.Encoding.GetEncoding("GB2312");
 43
        resp.AppendHeader(
"Content-Disposition""attachment;filename=" + FileName + ".xls");
 44
        resp.ContentType 
= "application/ms-excel";
 45
        
string colHeaders = "", ls_item = "";
 46

 47
        
//定義表對象與行對像,同時(shí)用DataSet對其值進(jìn)行初始化 
 48
        DataTable dt = ds.Tables[0];
 49
        DataRow[] myRow 
= dt.Select("");
 50
        
// typeid=="1"時(shí)導(dǎo)出為EXCEL格式文件;typeid=="2"時(shí)導(dǎo)出為XML格式文件 
 51
        if (typeid == "1")
 52
        
{
 53
            
//取得數(shù)據(jù)表各列標(biāo)題,各標(biāo)題之間以\t分割,最后一個(gè)列標(biāo)題后加回車符 
 54
            
//for (i = 0; colHeaders += dt.Columns[i].Caption.ToString() + "\t";
 55
            
//colHeaders += dt.Columns[i].Caption.ToString() + "\n")
 56
            
//    //向HTTP輸出流中寫入取得的數(shù)據(jù)信息 
 57
            
//    resp.Write(colHeaders);
 58
            
//逐行處理數(shù)據(jù)
 59
            for (int i = 0; i < gvUser.Columns.Count; i++)
 60
            
{
 61
                
if (i != 0 && i != 13 && i != 14 && i != 15)
 62
                
{
 63
                    ls_item 
+= this.gvUser.Columns[i].HeaderText + "\t";
 64
                    
//ls_item += row[i].ToString() + "\n";
 65
                    
//當(dāng)前行數(shù)據(jù)寫入HTTP輸出流,并且置空ls_item以便下行數(shù)據(jù)     
 66
                }

 67
            }

 68
            ls_item 
= ls_item.TrimEnd(new char[] '\t' });
 69
            ls_item 
+= "\n";
 70
            resp.Write(ls_item);
 71
            ls_item 
= "";
 72
            
foreach (DataRow row in myRow)
 73
            
{
 74
                
//在當(dāng)前行中,逐列獲得數(shù)據(jù),數(shù)據(jù)之間以\t分割,結(jié)束時(shí)加回車符\n 
 75
                for (int i = 0; i < gvUser.Columns.Count; i++)
 76
                
{
 77
                    
if (i != 0 && i != 13 && i != 14 && i != 15)
 78
                    
{
 79
                        
if (i == 3)
 80
                        
{
 81
                            ls_item 
+= ((DateTime)row[((BoundField)this.gvUser.Columns[i]).DataField]).ToString("yyyy年MM月dd日"+ "\t";
 82
                        }

 83
                        
else
 84
                        
{
 85
                            ls_item 
+= row[((BoundField)this.gvUser.Columns[i]).DataField].ToString() + "\t";//this.gvUser.Columns[i].HeaderText
 86
                        }
   
 87
                    }

 88
                }

 89
                ls_item 
= ls_item.TrimEnd(new char[] '\t' });
 90
                ls_item 
+= "\n";
 91
                resp.Write(ls_item);
 92
                ls_item 
= "";
 93
            }

 94
        }

 95
        
//else
 96
        
//{
 97
        
//    if (typeid == "2")
 98
        
//    {
 99
        
//        //從DataSet中直接導(dǎo)出XML數(shù)據(jù)并且寫到HTTP輸出流中 
100
        
//        resp.Write(ds.GetXml());
101
        
//    }
102
        
//}
103
        
//寫緩沖區(qū)中的數(shù)據(jù)到HTTP頭文件中 
104
        resp.End();
105
    }
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Net中導(dǎo)出數(shù)據(jù)到Excel(asp
Substitution控件
asp.net將新聞發(fā)布成靜態(tài)
C# 將數(shù)據(jù)導(dǎo)出到Excel匯總
.net實(shí)現(xiàn)微信公眾賬號接口開發(fā)
asp.net頁面間傳值的9種方式
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服