Styles Collection of Word Document


This code describes about collection of all styles within a active word document.

Styles collection of Active Word Document



This code describes about collection of all styles within a active word document


public void Styles_Collection(Office.IRibbonControl control)
{
try
{
object wUnit = Word.WdUnits.wdStory;
object missing = System.Reflection.Missing.Value;
string file_name = null;
file_name = Path.GetFileNameWithoutExtension(prow.WrdApp.ActiveDocument.FullName);

StreamWriter TextFile = new StreamWriter(prow.WrdApp.ActiveDocument.Path + "\\" + file_name + "-Styles.txt");

prow.WrdApp.Selection.HomeKey(ref wUnit, ref missing);
foreach (Word.Paragraph p in prow.WrdApp.ActiveDocument.Paragraphs)
{
p.Range.Select();
object sty = prow.WrdApp.Selection.get_Style();
Word.Style StyleName = (Word.Style)sty;
TextFile.WriteLine(StyleName.NameLocal);
}
TextFile.Close();
prow.WrdApp.ActiveWindow.Selection.WholeStory();
prow.WrdApp.Selection.HomeKey(ref wUnit, ref missing);
MessageBox.Show("Styles collection finished", "Styles", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
catch (Exception erd)
{
MessageBox.Show(erd.Message);
return;
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: