Consistency of Italic Words


Finding all italic words from a word document and display in a DataGridView

Consistency of Italic Words



This function finds all italic words from the active word document and displays in datagridview



private void gridviewForm_Load(object sender, EventArgs e)
{
int row = 0;
string ref_style = "";

this.Text = "Check consistency for Italic words";
this.dataGridView1.Columns[0].HeaderText = "Italic Words";

object wUnit = Word.WdUnits.wdStory;
object missing = System.Reflection.Missing.Value;
object wChar = Word.WdUnits.wdCharacter;
object pUnit = Word.WdUnits.wdWord;
object wDirs = Word.WdCollapseDirection.wdCollapseStart;
object wDire = Word.WdCollapseDirection.wdCollapseEnd;
object wExt = Word.WdMovementType.wdExtend;

object findtext = "";
object matchcase = false;
object matchwholeword = false;
object matchwildcards = false;
object soundslike = false;
object matchwordforms = false;
object forward = true;
object wrap = Word.WdFindWrap.wdFindStop;
object format = true;
object replacewith = missing;
object replace = false;
object replaceAll = missing;
object matchkashida = false;
object matchdiacritics = false;
object alehamza = false;
object matchcontrol = false;


prow.WrdApp.Selection.HomeKey(ref wUnit, ref missing);
prow.WrdApp.ActiveWindow.Selection.Collapse(ref wDirs);
prow.WrdApp.ActiveWindow.Selection.Find.ClearFormatting();
prow.WrdApp.ActiveWindow.Selection.Find.Replacement.ClearFormatting();
prow.WrdApp.ActiveWindow.Selection.Find.Font.Italic = 1;
prow.WrdApp.ActiveWindow.Selection.Find.Text = "";
prow.WrdApp.ActiveWindow.Selection.Find.Forward = true;
prow.WrdApp.ActiveWindow.Selection.Find.Wrap = Word.WdFindWrap.wdFindContinue;
prow.WrdApp.ActiveWindow.Selection.Find.Format = true;
prow.WrdApp.ActiveWindow.Selection.Find.MatchCase = false;
prow.WrdApp.ActiveWindow.Selection.Find.MatchWholeWord = false;
prow.WrdApp.ActiveWindow.Selection.Find.MatchWildcards = false;
prow.WrdApp.ActiveWindow.Selection.Find.MatchSoundsLike = false;
prow.WrdApp.ActiveWindow.Selection.Find.MatchAllWordForms = false;
while (prow.WrdApp.ActiveWindow.Selection.Find.Execute(ref findtext, ref matchcase, ref matchwholeword, ref matchwildcards, ref soundslike, ref matchwordforms, ref forward, ref wrap, ref format, ref replacewith, ref replaceAll, ref matchkashida, ref matchdiacritics, ref alehamza, ref matchcontrol) == true)
{
object sty = prow.WrdApp.Selection.get_Style();
Word.Style styleName = (Word.Style)sty;

dataGridView1.Rows.Add();
dataGridView1.Rows[row].Cells["Column1"].Value = prow.WrdApp.ActiveWindow.Selection.Text;
dataGridView1.Rows[row].Cells["Column2"].Value = prow.WrdApp.ActiveWindow.Selection.Paragraphs[1].Range.Text;
dataGridView1.Rows[row].Cells["Column3"].Value = "Click here";
row = row + 1;
prow.WrdApp.ActiveWindow.Selection.Collapse(ref wDire);

}
dataGridView1.Sort(dataGridView1.Columns["Column1"], System.ComponentModel.ListSortDirection.Ascending);
prow.WrdApp.Selection.HomeKey(ref wUnit, ref missing);
}
}

It goes to to the corresponding paragraph where the particular italic word is located



private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
int paraCnt = 0;
paraCnt = prow.WrdApp.ActiveDocument.Paragraphs.Count;
ArrayList ls = new ArrayList();
for (int z = 1; z <= paraCnt; z++)
{
ls.Add(prow.WrdApp.ActiveDocument.Paragraphs[z].Range.Text);
}

for (int y = 0; y <= ls.Count - 1; y++)
{
if (ls[y].ToString() != null)
{
if (ls[y].ToString().Trim() == dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString().Trim())
{
prow.WrdApp.ActiveDocument.Paragraphs[y + 1].Range.Select();
}
}
}
}
}


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: