SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*"; if(sfd.ShowDialog() == DialogResult.Cancel) return; bool bFileExisted = System.IO.File.Exists(sfd.FileName); System.IO.StreamWriter f_name = new System.IO.StreamWriter(sfd.FileName, bFileExisted, System.Text.Encoding.Default); //打印表头 if(!bFileExisted) f_name.WriteLine ("SJJK0101~~销售单据传入"); for(i_row=1;i_row<=outBlock.blk_info [1].row;i_row++) { outBlock.BlockNow = 2; f_name.WriteLine ("//单据{0}",i_row); f_name.WriteLine ("{0}~~{1}~~{2}~~{3}~~{4}~~{5}~~{6}~~{7}~~{8}",outBlock.GetColVal(i_row,"invoice_num_10").ToString(),outBlock.GetColVal(i_row,"invoice_seq_num").ToString(),outBlock.GetColVal(i_row,"settle_user_name").ToString(),outBlock.GetColVal(i_row,"tax_num").ToString(),outBlock.GetColVal(i_row,"sett_user_addr_name").ToString(),outBlock.GetColVal(i_row,"account_num").ToString(),outBlock.GetColVal(i_row,"all_remark").ToString(),efCB_shenhe.Text.ToString().Trim(),efCB_kaipiao.Text.ToString().Trim()); invoice_num = outBlock.GetColVal(i_row,"invoice_num_10").ToString(); for(r_row=1;r_row<=outBlock.blk_info[2].row;r_row++) { outBlock.BlockNow = 3; if(outBlock.GetColVal(r_row,"invoice_num_10").ToString() == invoice_num) { f_name.WriteLine ("{0}~~{1}~~{2}~~{3}~~{4}~~{5}~~{6}~~{7}~~{8}~~{9}~~{10}",outBlock.GetColVal(r_row,"chinese_prod_abbr").ToString()+outBlock.GetColVal(r_row,"sg_sign").ToString().Trim(),"吨",outBlock.GetColVal(r_row,"stand").ToString(),outBlock.GetColVal(r_row,"weight_ready_tot").ToString(),outBlock.GetColVal(r_row,"good_amount").ToString(),outBlock.GetColVal(r_row,"tax_rate").ToString(),"1601",outBlock.GetColVal(r_row,"interest").ToString(),outBlock.GetColVal(r_row,"amount_tax").ToString(),0,0); } } } f_name.Close(); this.EFMsgInfo = "写入txt成功!";