Skip to content

Instantly share code, notes, and snippets.

@Sarcross
Created November 5, 2016 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sarcross/b508ae839ee543c7a8048fd827baeee5 to your computer and use it in GitHub Desktop.
Save Sarcross/b508ae839ee543c7a8048fd827baeee5 to your computer and use it in GitHub Desktop.
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