Word Parsing - VB.net
Hello again,
I am wanting to read a certain style of heading from a Word document, once I find it I want to export it into a CSV file, or XML document.
When I am running the programme and I check the output file theres nothing in it can anybody help?
Below is the code which I am using.
Imports System.IO
Imports Word
Imports WordAutomation
Public Class Form1
Public wdoc As Word.Document
Public wapp As Word.Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declarations
Dim doc As New Word.Document
Dim wordApp As New Word.Application
Dim arguments As [String]() = Environment.GetCommandLineArgs()
Dim fsStream As New FileStream("a:\test.csv", FileMode.Append, FileAccess.Write)
Dim swWriter As New StreamWriter(fsStream)
doc = wordApp.Documents.Open("c:\temp\MCG1115A15")
wordApp.Visible = True
wordApp.Selection.EndKey(Word.WdUnits.wdStory)
wordApp.Selection.HomeKey(Word.WdUnits.wdStory, Word.WdKey.wdKeyShift)
'Variables
Dim count As Integer
count = wordApp.Selection.Range.ComputeStatistics(Word.WdS tatistic.wdStatisticLines)
'Variables
Dim i As Integer
For i = 0 To 2
wordApp.Selection.HomeKey(Word.WdUnits.wdLine)
If wordApp.Selection.Range.Style.ToString = "Test Heading 2" Then
swWriter.Write("Test Heading 2", wordApp.Selection.Range.Style.ToString)
swWriter.Close()
End If
wordApp.Selection.MoveDown(Word.WdUnits.wdLine, 1)
Next
End Sub
End Class
|