Esempio n. 1
0
 private void btnWrite_Click(object sender, RoutedEventArgs e)
 {
     if (txtPath.Text == "")
     {
         MessageBox.Show("Chưa chọn file Excel", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     else
     {
         try
         {
             //MessageBox.Show(bll.Left(bll.Right(txtPath.Text.Trim(), 16), 12)+'_'+bll.Right(bll.Left(CboSheet.SelectedValue.ToString().Trim(), 3),2));
             string FileName = "C:\\TEXT\\" + bll.XoaHetKyTuTrang(bll.Left(bll.Right(txtPath.Text.Trim(), 16), 12) + '_' + bll.Right(bll.Left(CboSheet.SelectedValue.ToString().Trim(), 3), 2)) + ".txt";
             //string[] arrStr = FileName.Split('\\');
             Encoding encode = Encoding.BigEndianUnicode;
             _fw = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None);
             StreamWriter sw = new StreamWriter(_fw, encode);
             foreach (DataRow row in dt.Rows)
             {
                 for (int i = 0; i < dt.Columns.Count; i++)
                 {
                     if (i + 1 < dt.Columns.Count)
                     {
                         sw.Write(row[i].ToString() + "$");
                     }
                     else
                     {
                         sw.Write(row[i].ToString());
                     }
                 }
                 sw.WriteLine();
             }
             sw.Close();
             MessageBox.Show("Export OK", "Mess", MessageBoxButton.OK, MessageBoxImage.Information);
             btnWrite.IsEnabled = false;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }