Bonjour,

J'arrive à ouvrir word, à y insérer une ligne de texte.
Maintenant comment faire pour un paragraphe, un tableau ou plusieurs ligne
J'ai essyé ce code qui ne mache pas :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
private void ImprimerWord(object parameter)
        {
            // create an instance of excel
            dynamic word = AutomationFactory.CreateObject("Word.Application");
            word.Visible = true;  // make it visible to the user.
 
            dynamic doc = word.Documents.Add();
            string insertText = "Hello Word from Silverlight 4!";
            dynamic range = doc.Range(0, 0);
            range.Text = insertText;
 
            if (oCommission.ID_TypeDossier == DataReference.TYPE_DOSSIER_RENOUVELLE)
                range.Text = "COMMISSION DE RENOUVELLEMENT DE BOURSES ET PRÊTS";
            else
                range.Text = "COMMISSION D'ATTRIBUTION DE BOURSES ET PRÊTS";
            range = doc.Range(1, 0);
            if (oCommission.ANNEE_SCOLAIRE.ID_LocalisationAide == DataReference.LOCALISATION_HNC)
                range.Text = "ETUDES SUPERIEURES HORS NOUVELLE-CALEDONIE";
            else
                range.Text = "ETUDES SUPERIEURES EN NOUVELLE-CALEDONIE";
            int iAn = Convert.ToDateTime(oCommission.ANNEE_SCOLAIRE.DateLimiteDepotDossier).Year;
            int iAnMoinsUn = iAn - 1;
            int iAnMoinsDeux = iAn - 2;
            int iAnMoinsTrois = iAn - 3;
            int i = 3;
            int j = 0;
            // iterate through our data source and populate the excel spreadsheet
            foreach (DOSSIER item in contextCombo.DOSSIERs)
            {
                j++;
                range = doc.Range(i, 0);
                try
                {
                    range.Text = j.ToString() + " " + item.ETUDIANT.CONTACT.Nom + " : " + item.ETUDIANT.CONTACT.DDN.ToString();
                }
                catch
                {
                    range.Text = "";
                }
 
                string strEtude1 = "";
                string strEtude2 = "";
                string strEtude3 = "";
                foreach (EFFECTUER_ETUDE oEff in item.ETUDIANT.EFFECTUER_ETUDE)
                {
                    if (iAnMoinsUn == (int)oEff.Annee)
                    {
                        strEtude1 = oEff.ETUDE.Libelle_Etude;
                    }
                    if (iAnMoinsDeux == (int)oEff.Annee)
                    {
                        strEtude2 = oEff.ETUDE.Libelle_Etude;
                    }
                    if (iAnMoinsTrois == (int)oEff.Annee)
                    {
                        strEtude3 = oEff.ETUDE.Libelle_Etude;
                    }
                }
                i++;
                range = doc.Range(i, 0);
                range.Text = "Son parcours scolaire : ";
                i++;
                range = doc.Range(i, 0);
                range.Text = iAnMoinsUn.ToString() + " : " + strEtude1;
                i++;
                range = doc.Range(i, 0);
                range.Text = iAnMoinsDeux.ToString() + " : " + strEtude2;
                i++;
                range = doc.Range(i, 0);
                range.Text = iAnMoinsTrois.ToString() + " : " + strEtude3;
            }
 
            i++;
        }
Voici le message d'erreur qu'il m'affiche :
MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext)
à MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue)
à MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args)
à MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args)
à System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
à System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__4(Object obj, InvokeMemberBinder binder, Object[] args)
à CallSite.Target(Closure , CallSite , Object , Int32 , Int32 )
à System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
à CallSite.Target(Closure , CallSite , Object , Int32 , Int32 )
à BoursesSuperieures.Models.PreparationViewModel.ImprimerWord(Object parameter)
à BoursesSuperieures.Models.DelegateCommand.Execute(Object parameter)
à System.Windows.Interactivity.InvokeCommandAction.Invoke(Object parameter)
à System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
à System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
à System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
à System.Windows.Controls.Primitives.ButtonBase.OnClick()
à System.Windows.Controls.Button.OnClick()
à System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
à System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
à MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Caused by: Exception de HRESULT : 0x800A1200

à MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext)
à MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue)
à MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args)
à MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args)
à System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
à System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__4(Object obj, InvokeMemberBinder binder, Object[] args)
à CallSite.Target(Closure , CallSite , Object , Int32 , Int32 )
à System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
à CallSite.Target(Closure , CallSite , Object , Int32 , Int32 )
à BoursesSuperieures.Models.PreparationViewModel.ImprimerWord(Object parameter)
à BoursesSuperieures.Models.DelegateCommand.Execute(Object parameter)
à System.Windows.Interactivity.InvokeCommandAction.Invoke(Object parameter)
à System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
à System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
à System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
à System.Windows.Controls.Primitives.ButtonBase.OnClick()
à System.Windows.Controls.Button.OnClick()
à System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
à System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
à MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Merci de m'aider.