Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Программирование и базы данных (http://forum.oszone.net/forumdisplay.php?f=21)
-   -   Поиск строки с определенным форматированием в документе Word (http://forum.oszone.net/showthread.php?t=335448)

tumanovalex 22-06-2018 21:38 2819181

Поиск строки с определенным форматированием в документе Word
 
В функции
Код:

public void FindString()
{
  Object missing = System.Reflection.Missing.Value;
  Object confConv = false;
  Object readOnly = true;
  Object isVisible = false;
  Object saveChanges = false;
  Word.Application word = new Word.Application();
  word.Visible = false;
  Word.Document doc = null;
  Word.Range docRange;
  Object MatchCase = false;
  Object MatchWholeWord = false; // !!! может быть ошибка, если true
  Object MatchWildcards = false;
  Object MatchSoundsLike = false;
  Object MatchAllWordForms = false;
  Object Forward = true;
  Object Wrap = false;
  Object Format = true;
  Object ReplaceWith = false;
  Object Replace = false;
  Object MatchKashida = false;
  Object MatchDiacritics = false;
  Object MatchAlefHamza = false;
  Object MatchControl = false;
  string strFileOldFull = "";
  foreach (string strFile in strDocFileName)
  {
    Object filename = strFile;
    try
    {
      doc = word.Documents.Open(ref filename, ref confConv, ref readOnly);
    }
    catch (Exception)
    {
      strMes = "\nНе удается открыть файл --- " + strFile + " ---\n";
      Console.WriteLine(strMes);
      ioWriterFind.WriteLine(strMes);
      ((Word._Document)doc).Close(ref saveChanges, missing, missing);
      continue;
    }
    Console.WriteLine('\n' + strFile + '\n');
    foreach (string strFindFull in strArrFind)
    {
      Object FindText = strFindFull;
      for(int nSec = 1; nSec <=  doc.Sections.Count; nSec++)
      {
        docRange = doc.Sections[nSec].Range;
        while(docRange.Find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards,
                                    ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap,
                                    ref Format, ref ReplaceWith, ref Replace, ref MatchKashida,
                                    ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))

        {
          if (strFile != strFileOldFull)
          {
            ioWriterFind.WriteLine("\n--- " + strFile + " ---\n");
            strFileOldFull = strFile;
          }
          Console.WriteLine(strFindFull);
          ioWriterFind.WriteLine(strFindFull);
        } // while(docRange.Find.Execute
      } // for(nSec = 1; nSec <=  doc.Sections.Count)
    } // foreach (string strFind in strListFind)
    ((Word._Document)doc).Close(ref saveChanges, missing, missing);
  } //foreach(string strFile in strArrFindFileName)
  ((Word._Application)word).Quit(ref saveChanges);
  ioWriterFind.Close();
} // FindString()

идет поиск строки. А как задать поиск строки с учетом ее форматирования? Например, найти строку с подчеркиванием, полужирную, наклонную или же со всеми этими форматированиями вместе? Проект прикрепил.


Время: 13:00.

Время: 13:00.
© OSzone.net 2001-