chetan Allipur

chetan Allipur

  • 1.4k
  • 541
  • 82.2k

How to search Hidden Styles in word using VSTO in c#

Feb 6 2019 12:57 AM
I am not able to search Hidden Styles in word using VSTO c#.
I have two styles "Instructions" and "Guidance" in my word document.
 
Here I used code:
  1. public bool CheckInstructionText()  
  2. {  
  3. try  
  4. {  
  5. istoCheckInstructionsandGuidence = false;  
  6. bool ischeckforInstructions = false;  
  7. bool ischeckforGuidence = false;  
  8. Microsoft.Office.Interop.Word.Application app = Globals.ThisAddIn.Application;  
  9. Microsoft.Office.Interop.Word.Document doc1 = app.ActiveDocument;  
  10. Microsoft.Office.Interop.Word.Selection wordSelection = app.ActiveWindow.Selection;  
  11. Find fnd = doc1.Content.Find;//.Range.Find;  
  12. fnd.ClearFormatting();  
  13. fnd.Font.Hidden = 1;  
  14. fnd.Replacement.ClearFormatting();  
  15. fnd.Text = "";  
  16. fnd.Replacement.Text = "";  
  17. fnd.Forward = true;  
  18. fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;  
  19. fnd.Format = true;  
  20. fnd.set_Style("Instructions");  
  21. ischeckforInstructions = fnd.Execute();  
  22. fnd.ClearFormatting();  
  23. fnd.Font.Hidden = 1;  
  24. fnd.Replacement.ClearFormatting();  
  25. fnd.Text = "";  
  26. fnd.Replacement.Text = "";  
  27. fnd.Forward = true;  
  28. fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;  
  29. fnd.Format = true;  
  30. fnd.set_Style("Guidance");  
  31. ischeckforGuidence = fnd.Execute();  
  32. if (ischeckforInstructions || ischeckforGuidence)  
  33. {  
  34. istoCheckInstructionsandGuidence = true;  
  35. }  
  36. }  
  37. catch  
  38. {  
  39. }  
  40. return istoCheckInstructionsandGuidence;  
  41. }  
Please anyone know the answer please reply me.
 
Thanks