Example #1
0
 private void btnRead_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
         object miss = System.Reflection.Missing.Value;
         //object path = @"C:\TEXT\Cauhoi.docx";
         string filename = @"C:\TEXT\dapan.txt";
         object path     = txtPath.Text;
         object readOnly = true;
         Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
         string totaltext = "";
         for (int i = 6; i < docs.Paragraphs.Count; i += 5)
         {
             //totaltext += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
             totaltext += docs.Paragraphs[i + 1].Range.Text;
             //MessageBox.Show(totaltext);
         }
         //Console.WriteLine(totaltext);
         bll.WriteToText(totaltext, filename);
         docs.Close();
         word.Quit();
         MessageBox.Show("OK ", "Mess", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error + " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }