I want to count the total number of lines of the word document (.doc /.docx).
In my class, I added a reference to the COM library Microsoft.Office.Interop.Word
through which I am counting the document's total word count.
With reference to the this Lines.Count Property documentation, the library also provides a lines count option in the latest version.
But unfortunately, I am unable to find the Lines
interface or property in the whole library.
Is there any other way to get the total number of lines of the MS Word document as shown in the image below?
Method for words count (just for reference)
public int GetWordsCountFromWordFile(string wordFile)
{
try
{
if (!string.IsNullOrEmpty(wordFile))
{
var application = new Application();
var document = application.Documents.Open(wordFile, ReadOnly: true);
int count = document.Words.Count;
document.Close();
return count;
}
return 0;
}
catch (Exception ex)
{
LogWriter.ErrorLogWriter(nameof(Client), nameof(TaskHelper), nameof(GetWordsCountFromWordFile), "int", ex.Message);
return 0;
}
}