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 47
|
private void ProcessFileWord(SPFile file)
{
Microsoft.Office.Interop.Word._Document document = null;
object missing = System.Reflection.Missing.Value;
object fileName = this.webSiteUrl + "/" + file.Url;
try
{
if (this.wordApplication == null)
{
wordApplication = new Microsoft.Office.Interop.Word.Application();
wordApplication.Visible = false;
}
//Ouverture du document
document = wordApplication.Documents.Open(ref fileName,
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);
if (document != null)
{
this.InitWordContentControl(document, document.ContentControls);
foreach (Microsoft.Office.Interop.Word.Section section in document.Sections)
{
foreach (Microsoft.Office.Interop.Word.HeaderFooter header in section.Headers)
this.InitWordContentControl(document, header.Range.ContentControls);
foreach (Microsoft.Office.Interop.Word.HeaderFooter footer in section.Footers)
this.InitWordContentControl(document, footer.Range.ContentControls);
}
// Sauvegarde du document
document.Save();
}
}
finally
{
// Fermeture du document
if (document != null)
document.Close(ref missing, ref missing, ref missing);
}
} |
Partager