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 55 56
|
using System.Runtime.InteropServices;
{...}
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Envoyer_Click(object sender, EventArgs e)
{
object M = System.Reflection.Missing.Value;
Excel._Application xlApp = null;
try
{
try
{
// Recherche si une instance Excel est active
xlApp = Marshal.GetActiveObject("Excel.Application") as Excel.Application;
}
catch
{
// Si aucune instance d'Excel n'est active, demande l'ouverture du fichier
xlApp = new Excel.Application();
xlApp._FindFile();
}
finally
{
xlApp.Visible = true;
try
{
// Lance une macro
xlApp.Run("MacroLanceeParDotnet", this.txtArg1.Text.ToString(), this.txtArg2.Text.ToString(), M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, M);
}
catch (Exception ex1)
{
throw new Exception("Erreur : " + ex1.Message.ToString());
}
finally
{
//xlClasseur.Save(); // Enregistre les modifs des cellules
//xlApp.Quit(); // On met fin au pilotage
}
}
}
catch (Exception ex)
{
throw new Exception("Erreur : " + ex.Message.ToString());
}
}
} |