The code sample gets the line count in a word file. It uses the Word namespace. The dll file related to this namespace is given as an attachment.
The function takes the path of the word file as it's argument.
Imports System.IO Imports Microsoft.VisualBasic Imports Word Imports System.Math Namespace BLL Public Class WordCount
Public Function lineCount(ByVal fileNamepath As String) As Double
Try Dim missing As Object = Type.Missing Dim appWord As Word.Application = New Word.Application Dim aDoc As Word.Document
aDoc = appWord.Documents.Open(fileNamepath, missing, _ missing, missing, missing, missing, missing, missing, _ missing, missing, missing, missing)
Dim str As String = aDoc.Content.Text Dim i As Integer i = aDoc.Words.Count Dim c As Char Dim line As Integer = 0 Dim lCount As Double Dim ii As Integer For Each c In str If ((Asc(c) >= 32 AndAlso Asc(c) <= 126) Or Asc(c) = 9 Or Asc(c) = 146) Then line += 1 Else Asc(c) 'Dim log As New BLL.FileOperation 'log.WriteLog(Asc(c)) ii = ii + 1 End If Next lCount = Math.Ceiling(line / 65) aDoc.Close() appWord.Quit() Return lCount Catch ex As Exception Throw End Try End Function
End Class End Namespace
AttachmentsWord DLL (19664-2167-Interop.Word.dll)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|