生成CSV

来源:互联网 发布:网络电视直播系统 编辑:程序博客网 时间:2024/05/18 03:34
        string strTitle = "行,制造,机种编码,类型\r\n";
        StringBuilder strWriter = new StringBuilder();
        strWriter.Append(strTitle);
        foreach (GridViewRow row in this.gvPdList.Rows)
        {
            // 行号
            strWriter.Append(row.Cells[0].Text.ToString().Replace(" ", "").Replace(",", ",").Replace("\r\n", "") + ",");
            // LOT编号
            strWriter.Append(row.Cells[1].Text.ToString().Replace(" ", "").Replace(",", ",").Replace("\r\n", "") + ",");
            // 机种编号
            strWriter.Append(row.Cells[2].Text.ToString().Replace(" ", "").Replace(",", ",").Replace("\r\n", "") + ",");
            // 保税类型
            strWriter.Append(row.Cells[3].Text.ToString().Replace(" ", "").Replace(",", ",").Replace("\r\n", "") + "\r\n");
        }
        Response.AppendHeader("Content-Disposition", "attachment;filename=BL_Relieve_LotNo.csv");
        Response.ContentType = "application/csv";
        Response.Charset = "ANSI";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding(0);
        Page.EnableViewState = false;
        Response.Write(strWriter.ToString());
        Response.End();
原创粉丝点击