Programmatically reading a Microsoft Word document
coldfusion, javascript, ms-word
Solution
I did this a few years back using VBA, refer to this article. Here is an excerpt that parses each paragraph of a document:
Public Sub ParseLines()
Dim singleLine As Paragraph
Dim lineText As String
For Each singleLine In ActiveDocument.Paragraphs
lineText = singleLine.Range.Text
'// parse the text here...
Next singleLine
End Sub
Problem
I have my students submit their Microsoft Word assignments to a ColdFusion 10 server. I'd like to write an error checker to check for common mistakes like not having a page number in the header, the name of the school on the title page, their name on the title page, etc. I specify a lot of APA rules. Example: The phrase "Running head:" must be in the header section of page 1 but not the rest of the paper. I assign a point value to each rule. Ideally, this error checker would run when they submit the assignment and tell them immediately. That might require using ``` parser.parseFromString(str, "text/xml"); ``` But as an alternate, if I could write a program that I run to check for errors, that could help automate my grading. In other words, using Microsoft Access or Visual Studio. But I don't want to do that because then I'd have to have Visual Studio on the server and I don't think that's going to be feasible. The last option would be to download all the papers off the server and run a program locally, which is one step better than grading everything manually.