Пример #1
0
        public static void wordParsePara(Document doc, Kruti2uni kr)
        {
            int count = doc.Paragraphs.Count;

            for (int i = 1; i <= count; i++)
            {
                Range rg = doc.Paragraphs[i].Range;
                rg.Find.ClearFormatting();
               // rg.Find.MatchWildcards = true;
                rg.Find.Font.Name = "Kruti Dev 010";
                rg.Find.Execute();
                rg.Text = kr.converter(rg.Text);
            }
        }
Пример #2
0
        public static void wordParse(Document doc, Kruti2uni kr)
        {
            //Range rg = doc.Range();
            Selection sl = doc.Application.Selection;
               // sl1.Find.ClearFormatting();
            //sl.Find.MatchWildcards = true;
               // sl1.Find.Font.Name = "Kruti Dev 010";
               // rg.Find.Replacement.ClearFormatting();
               // sl.Find.Text = @"[ \t]";

            bool result = true;
            try
            {
                while (result)
                {
                  //  Selection sl = doc.Application.Selection;
                   // sl = doc.Application.Selection;
                    sl.Find.ClearFormatting();
                    sl.Find.Font.Name = "Kruti Dev 010";
                    // http://social.msdn.microsoft.com/Forums/windows/en-US/82b56ef5-ae05-4fda-a963-25a026c559a4/wordselectionfindexecute-search-and-replace-only-work-on-the-first-search-but-not-on
                    sl.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

                   result= sl.Find.Execute();

                   if (result)
                   {
                       sl.Text = kr.converter(sl.Text);
                       sl.Font.Name = "Mangal";
                       sl.Font.Size = sl.Font.Size ;
                       //sl.Next().Select(); ;

                   }
                }
            }
            catch (Exception ex) { }
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            label4.Text = "";
            Kruti2uni kr = new Kruti2uni();
             Document doc;

             try
             {
                 try
                 {
                     FileStream fs;
                     fs =
                          File.Open(this.textBox1.Text,
            FileMode.Open, FileAccess.Read, FileShare.None);
                     fs.Close();
                     fs.Dispose();
                     fs = null;
                 }
                 catch (Exception ex)
                 {

                     MessageBox.Show("File already open. Trying to close. Shall close all other open documents. Please save them.");
                     try
                     {
                         Process[] pro = Process.GetProcessesByName("WINWORD");
                         if (pro.Length > 0)
                         {
                             foreach (Process p in pro)
                             {
                                 p.Kill();
                             }
                         }
                     }
                     catch (Exception ex1) { }
                 }
                 Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
                 doc = app.Documents.Open(this.textBox1.Text, Visible:true);
                 string filename = System.IO.Path.GetFileNameWithoutExtension(this.textBox1.Text);
                 string directory = System.IO.Path.GetDirectoryName(this.textBox1.Text);
                 label4.Text = "Processing ..";
                 //Processing prc = new Processing();
                // prc.ShowDialog();
                 WordParse.wordParse(doc, kr);
                // doc.Save();
                 String str = directory + "\\" + filename + "_unicode" + ".doc";
                   doc.SaveAs(str);
                 doc.Close();
                // prc.Close();
                 label4.Text = "Output saved at:  "+str;

                 //app.Quit();
             }
             catch (Exception ex) {
                 MessageBox.Show("Error in execution: " + ex.Message);  }
            /*
             try
             {
                 Characters chr = doc.Characters;
                 int i = 1;
                 bool v = Regex.Match("v", @"\s").Success;
                 int counter = 1;
                 while (i < chr.Count)
                 {
                     while (chr[i].Font.Name != "Kruti Dev 010") { i++;  }
                     int j = counter;
                     int k = i;
                     String str = "";
                     while (!Regex.Match(chr[i].Text, @"\s").Success && chr[i].Font.Name == "Kruti Dev 010")
                     {
                         i++;
                         str += chr[i].Text;
                     }
                     this.label2.Text = str;
                    // this.label2.Font.Name = "Kruti Dev 010";
                     while (Regex.Match(chr[k].Text, @"\s+").Success) i++;
                     Range rg = doc.Range(i, k);
                     String newstr = kr.converter(str);
                     rg.Text = newstr;
                     /*
                     rg.Find.Text = str;
                     rg.Find.Replacement.ClearFormatting();
                     rg.Find.Replacement.Text = newstr;
                     rg.Find.Replacement.Font.Name = "Mangal";
                     rg.Find.Execute();

                     counter = i + newstr.Length - str.Length;

                     i++;

                 }
             }
             catch (Exception ex) { }
            */
            /*
             Words wd = doc.Words;
             for (int i = 0; i < wd.Count; i++)
             {
                 if (wd[i + 1].Font.Name == "Kruti Dev 010")
                 {
                     doc.Words[i + 1].Text = kr.converter(wd[i+1].Text);
                     doc.Words[i + 1].Font.Name = "Mangal";
                    // doc.Words[i + 1].Font.Size = (doc.Words[i + 1].Font.Size) / 2;
                 }
             }
             * */
            // doc.Range().Text = kr.converter(doc.Range().Text);
             //doc.Range().Font.Name = "Mangal";
        }