public void ExportTxt() { string SaveOrderPath = System.Configuration.ConfigurationManager.AppSettings["BMBExportTxtPath"].ToString();//获取要导出文件的路径 string OrderNameTxT =txtOrderNO.Text+"-"+ DateTime.Now.Year+"-" + DateTime.Now.Month +"-"+ DateTime.Now.Day +"-"+ DateTime.Now.Hour +"-"+ DateTime.Now.Minute +"-"+ DateTime.Now.Second+ "-" + "CLA"+ ".txt"; //导出文件TxT StreamWriter sw=null; try { if (SaveOrderPath.Substring(SaveOrderPath.Length - 1) == "\\")//Substring是截取判断 { SaveOrderPath = SaveOrderPath + OrderNameTxT; } else { SaveOrderPath = SaveOrderPath + "\\" + OrderNameTxT; } sw = new StreamWriter(SaveOrderPath, false, System.Text.Encoding.Unicode); sw.Flush(); string stringListTotal = ""; StringBuilder strAppTotal = new StringBuilder(); string strHeader = ""; strHeader += "ItemNO" + "\t"; strHeader += "OrderNo" + "\t"; strHeader += "PONo" + "\t"; strHeader += "StyleName" + "\t"; strHeader += "StyleNo" + "\t"; strHeader += "W1" + "\t"; strHeader += "Qty" + "\t"; StringBuilder strApp = new StringBuilder(); for (int j = 1; j <= 57; j++) { strHeader += "C" +j+ "\t"; } sw.WriteLine(strHeader); //第一步写入的头部 }