zoukankan      html  css  js  c++  java
  • winform导出csv

    public void ExportToSvc1(string strFileName)
    {
    string strPath = strFileName + ".csv";

    StringBuilder strValue = new StringBuilder();
    int i = 0;
    try
    {
    Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
    sfd.Filter = "导出文件 (*.csv)|*.csv";
    sfd.FilterIndex = 0;
    sfd.RestoreDirectory = true;
    sfd.Title = "导出文件保存路径";
    sfd.FileName = strFileName + ".csv";
    sfd.ShowDialog();
    string strFilePath = sfd.FileName;

    if (strFilePath != "")
    {
    if (File.Exists(strFilePath))
    {
    File.Delete(strFilePath);
    }

    StreamWriter sw = new StreamWriter(new FileStream(strFilePath, FileMode.CreateNew), Encoding.GetEncoding("GB2312"));
    DataSet ds = new DataSet();
    WriteHeader1(sw);
    //Date,Line,BatchNo,SackNo.,Shipping No,Weight,
    ds = plb.SelectFlightDetailMonthExport(this.dateTimePicker4.Value.ToString("yyyyMM"), cbbline1.SelectedItem.ToString());
    for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
    {
    StringBuilder strColu = new StringBuilder();
    string temp = ds.Tables[0].Rows[i][0].ToString();
    strColu.Append(ds.Tables[0].Rows[i][0]);
    strColu.Append(",");
    string temp1 = ds.Tables[0].Rows[i][1].ToString();
    strColu.Append(ds.Tables[0].Rows[i][1]);
    strColu.Append(",");

    strColu.Append(ds.Tables[0].Rows[i][2]);
    strColu.Append(",");

    strColu.Append(ds.Tables[0].Rows[i][3]);
    strColu.Append(",");
    strColu.Append(ds.Tables[0].Rows[i][4]);
    strColu.Append(",");
    strColu.Append(ds.Tables[0].Rows[i][5]);
    strColu.Append(",");
    sw.WriteLine(strColu);

    }
    sw.Close();
    }
    else
    {

    }

    }
    catch (Exception ex)
    {
    throw ex;
    }

    }

    private void WriteHeader1(StreamWriter sw)
    {
    string strHeader = "Date,Line,BatchNo,SackNo.,Shipping No,Weight,";
    sw.WriteLine(strHeader);
    }

  • 相关阅读:
    CentOS6+nginx+uwsgi+mysql+django1.6.6+python2.6.6
    CentOS 6.5下安装Python+Django+Nginx+uWSGI
    python学习之旅
    Gitlab安装操作说明书
    快速上手git gitlab协同合作
    在centos6.3用yum安装redis
    CentOS 6.5 下安装 Redis 2.8.7
    Ruby Gems更换淘宝源方法
    Apache 日志分析(一)
    Apache 日志分析(二)
  • 原文地址:https://www.cnblogs.com/panjuan/p/4757608.html
Copyright © 2011-2022 走看看