Refer the below query and change accordingly.
object filename = @"F:\Test.docx";
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
doc = app.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
List<string> data = new List<string>();
for (int i = 0; i < doc.Paragraphs.Count; i++)
{
string temp = doc.Paragraphs[i + 1].Range.Text.Trim();
if (temp != string.Empty)
{
data.Add(temp);
}
}
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)), new DataColumn("Character"), new DataColumn("Number", typeof(int)) });
for (int i = 0; i < data.Count; i++)
{
string txt = data[i].ToUpper();
char chr = txt[0];
int number = (int)chr;
int value = 0;
if (number > 1039)
{
value = (number + 1) - 1040;
}
else
{
value = (number + 1) - 65;
}
dt.Rows.Add((i + 1), txt , value);
}
gvDetails.DataSource = dt;
gvDetails.DataBind();
doc.Close(ref missing, ref missing, ref missing);
OutPut
Id | Character | Number |
1 |
А |
1 |
2 |
Б |
2 |
3 |
В |
3 |
4 |
Г |
4 |
5 |
Д |
5 |
6 |
E |
5 |
7 |
C |
3 |
8 |
A |
1 |
9 |
B |
2 |
10 |
C |
3 |
11 |
D |
4 |
12 |
E |
5 |