Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically reading a Microsoft Word document

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.

like image 954
Phillip Senn Avatar asked Feb 01 '13 21:02

Phillip Senn


People also ask

Can you get a Word document to read to you?

Listen to your documents with Speak Speak is a built-in feature of Word, Outlook, PowerPoint, and OneNote. Speak reads aloud only the text you select. Read Aloud reads the entire document starting from your cursor location like an audiobook.


1 Answers

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
like image 98
Alberto Ponte Avatar answered Oct 12 '22 08:10

Alberto Ponte