IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Silverlight Discussion :

Piloter word automation


Sujet :

Silverlight

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Juin 2010
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 45
    Par défaut Piloter word automation
    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.

  2. #2
    Membre Expert
    Avatar de Samuel Blanchard
    Homme Profil pro
    Expert .NET
    Inscrit en
    Février 2010
    Messages
    1 504
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France

    Informations professionnelles :
    Activité : Expert .NET

    Informations forums :
    Inscription : Février 2010
    Messages : 1 504
    Par défaut
    Bonjour,

    J'arrive à ouvrir word, à y insérer une ligne de texte.
    Maintenant comment faire pour un paragraphe, un tableau ou plusieurs ligne
    Si tu arrives à ouvrir Word et écrire une ligne de texte, c'est que l'AutomationFactory fonctionne correctement. Les problèmes que tu rencontres ne sont donc pas liés à Silverlight mais bien à l'utilisation de l'ActiveX de Word. Je me demande donc si tu postes au bon endroit ?

Discussions similaires

  1. [Débutant] Piloter l'automation de Word avec C#
    Par MoThA dans le forum C#
    Réponses: 2
    Dernier message: 28/10/2013, 22h46
  2. [AC-2003] Automation: Piloter Word en VBA.
    Par Chrysostome dans le forum VBA Access
    Réponses: 2
    Dernier message: 15/03/2013, 12h16
  3. Piloter Word via JS (OLE Automation)
    Par nox75 dans le forum Général JavaScript
    Réponses: 12
    Dernier message: 23/01/2009, 13h19
  4. Piloter Word 2000 et Word XP (TWordApplication)
    Par gmc dans le forum API, COM et SDKs
    Réponses: 9
    Dernier message: 30/07/2004, 13h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo