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 48 49 50 51 52 53 54
|
public ActionResult etat(emp empl)
{
//var recherche_emp = (from c in entity.emps
// where c.mat == id.mat
// select c).FirstOrDefault();
try
{
// connexion à Word
Microsoft.Office.Interop.Word.Application msWord = new Microsoft.Office.Interop.Word.Application();
// Afficher à l'utilisateur l'application WORD ou non
msWord.Visible = true;
// déclaration de l objet Missing
Object M = Missing.Value;
// Création d'un nouveau document word
Microsoft.Office.Interop.Word.Document newDoc;
// Attribution du nom au document nouvellement crée
Object file = "g:" + "fichier" + ".docx";
// Création du nouveau document WORD
// newDoc = msWord.Documents.Add(ref M, ref M, ref M, ref M);
newDoc = msWord.Documents.Open(ref file, ref M, ref M, ref M, ref M, ref M, ref M,
ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M);
newDoc.Tables[1].Cell(1, 2).Range.Text = empl.nom;
// Sauvegarde du document nouvellement crée
newDoc.SaveAs(ref file, ref M, ref M, ref M, ref M, ref M, ref M,
ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M);
// on ferme le document WORD (
// a utiliser si lapplication nest pas visible)
// newDoc.Close(ref M, ref M, ref M);
// on quitte l'application WORD
// arrêt de la connexion à l'application
// (a utiliser si lapplication nest pas visible)
//msWord.Quit(ref M, ref M, ref M);
}
catch (System.Runtime.InteropServices.COMException error)
{
return RedirectToAction("recherche");
}
return RedirectToAction("recherche");
} |
Partager