标签:
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);
}
标签:
原文地址:http://www.cnblogs.com/panjuan/p/4757608.html