Bonjour à tous, je rencontre de gros probleme en voulant manipuler excel via C#.


Je m'explique, je crée de nouvelle fonctions utlisateur dans Excel, ces fontions sont définit en C#.

Le code que j'utilise:



[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class MyFunctions
{

private Excel.Application _excel;

public MyFunctions()
{
// Get a reference to the current Excel !
_excel = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application") as Excel.Application;
}


public string toto()
{
try
{
_excel.ScreenUpdating = false;
_excel.Cells[2, 5] = "Rah !!!";
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
_excel.ScreenUpdating = true;
}
return "";
}

...
...
}


Une fois compiler je l'enregistre dans le service Automation via Excel. Une fois enregistré je peux donc appeler ma fonction toto-> (=toto())

Cependant, arrivé au niveau de " _excel.Cells[2, 5] = "Rah !!!"; " il sort une exception HResult ....

Quelqu'un a une idée ?

Joel