chetan Allipur

chetan Allipur

  • NA
  • 541
  • 169.1k

How to get fastest Heading Number from Word document.

Dec 4 2017 3:53 AM
How to get fastest Heading Number from Word document.
My code is getting too slow when we have more than 20 pages.
 
Here is my code
 
foreach (Paragraph paragraph in Globals.ThisAddIn.Application.ActiveDocument.Paragraphs)
{
if ((paragraph.Range.get_Style() as Style) != null)
{
if ((paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 1") || (paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 2") ||
(paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 3") || (paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 4") ||
(paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 5") || (paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 6") ||
(paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 7") || (paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 8") ||
(paragraph.Range.get_Style() as Style).NameLocal.StartsWith("Heading 9"))
{
string GetSections = paragraph.Range.ListFormat.ListString;
if (GetSections != "")
{
cbGetSections.Items.Add(GetSections);
RibbonTab.ConstantValue.Add(GetSections);
}
}
}
}
 We are using each paragraph that's why it is getting slow.
 
Please send me the fastest code to get Heading Numbers.