Created
November 5, 2016 16:04
-
-
Save Sarcross/b508ae839ee543c7a8048fd827baeee5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Office.Interop.Word; | |
using RGiesecke.DllExport; //For DllExport | |
using System.Runtime.InteropServices; //For CallingConvention | |
namespace Parser | |
{ | |
class DocumentParser | |
{ | |
[DllExport("getDocumentText", CallingConvention = CallingConvention.Cdecl)] | |
static string[] getDocumentText(string doc) | |
{ | |
Application application = new Application(); | |
try | |
{ | |
Document document = application.Documents.Open(doc); | |
string[] paragraphs = new string[document.Paragraphs.Count]; | |
int position = 0; | |
foreach(Paragraph para in document.Paragraphs) { | |
paragraphs[position++] = para.Range.Text; | |
Console.WriteLine(paragraphs[position - 1]); | |
} | |
// Close word. | |
application.Quit(); | |
return paragraphs; | |
} | |
catch(System.Runtime.InteropServices.COMException) | |
{ | |
application.Quit(); | |
return null; | |
} | |
} | |
[DllExport("testLib", CallingConvention = CallingConvention.Cdecl)] | |
static void testLib() | |
{ | |
Console.WriteLine("Test Successful"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment