1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
programme principal :
.........
application = new WordUtils ();
application.CreateApplication ();
.........
boucle for sur tous les fichiers {
.........
objet = application.recupereObjetDoc (fichierWord);
.........
}
public class WordUtils
{
private object missing = System.Reflection.Missing.Value;
private Microsoft.Office.Interop.Word.Application application;
private Document document;
..........
public void CreateApplication()
{
application = new Microsoft.Office.Interop.Word.Application();
application.Visible = false;
}
public string recupereObjetDoc (object filePath) {
try {
document = application.Documents.Open (ref filePath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
Microsoft.Office.Interop.Word.Paragraph paraNo2 = document.Content.Paragraphs[3];
if ((paraNo2.Range.End - paraNo2.Range.Start) > 1) {
string result = paraNo2.Range.Text;
((_Document) document).Close (ref missing, ref missing, ref missing);
return result;
} else {
if (document != null)
((_Document) document).Close (ref missing, ref missing, ref missing);
return null;
}
} catch (Exception ex) {
return null;
}
} |
Partager