Interopérabilité Word/Excel et COMException
Bonjour CSharpers
Voici mon problème. Je veux lire un document Word pour récupérer certaines informations. Pour ce faire, j'utilise l'interopérabilité. Je teste, Ok, ça marche.
Maintenant, je veux pouvoir utiliser ces données récupérées pour écrire un fichier Excel, toujours avec l'interopérabilité. Voici le code de la classe principale:
Code:
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StudyPlanReader;
using DmpkFilesGenerator;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string cwd = @"C:\Documents and Settings\gldavid\Desktop";
string file = @"C:\Documents and Settings\gldavid\My Documents\Documents\MyDoc.doc";;
StudyPlanParser target = new StudyPlanParser(file);
try
{
Console.WriteLine("Reading Word");
target.Open();
target.Parse();
string sn = target.StudyNumber;
List<String>clots = target.CompoundLots;
target.Close();
Console.WriteLine("Creating Excel");
CalculationsSummaryCreator csc = new CalculationsSummaryCreator(sn, clots, cwd);
csc.CreateFile();
Console.WriteLine("OK...");
Console.ReadKey();
}
catch (Exception e)
{
target.Close();
Console.WriteLine("{0}", e.Message);
Console.WriteLine("{0}", e.Source);
Console.WriteLine("{0}", e.StackTrace);
Console.WriteLine("...");
Console.ReadKey();
}
}
}
} |
Le problème est qu'en cours d'exécution, j'ai l'erreur suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
System.Runtime.InteropServices.COMException was unhandled
Message=The remote procedure call failed and did not execute. (Exception from HRESULT: 0x800706BF)
Source=StudyPlanReader
ErrorCode=-2147467259
StackTrace:
at StudyPlanReader.AWordReader.Close() in C:\Documents and Settings\dbourgais\my documents\visual studio 2010\Projects\DmpkExcelCalculationsLib\StudyPlanReader\AWordReader.cs:line 74
at ConsoleApplication1.Program.Main(String[] args) in C:\Documents and Settings\dbourgais\my documents\visual studio 2010\Projects\DmpkExcelCalculationsLib\ConsoleApplication1\Program.cs:line 33
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: |
J'ai oublié quelque chose ?
Merci d'avance de votre aide.
@++