Word C#

pete87150 Messages postés 7 Date d'inscription vendredi 12 mars 2004 Statut Membre Dernière intervention 24 mars 2004 - 15 mars 2004 à 16:37
hamden79 Messages postés 1 Date d'inscription vendredi 16 avril 2004 Statut Membre Dernière intervention 23 juin 2004 - 23 juin 2004 à 12:40
Bonjour,

Je voudrais savoir comment ouvrir un document Word en C#, quelle référence ou directive utiliser etc.

Voici mon code simplifié qui ne marche pas :

<%@ WebService language="C#" class="Bonjour" %>

using System.IO;
using System;
using System.Web.Services;
using System.Xml.Serialization;

namespace fichierWord
{
public class Bonjour {

[WebMethod]
public int Fichier(string parametres)
{
Word.Application App= new Word.ApplicationClass();

return 1;
}
}
}

Ca me met l'erreur suivante :

Compiler Error Message: CS0246: The type or namespace name 'Word' could not be found (are you missing a using directive or an assembly reference?)

Merci d'avance

Pierre

2 réponses

TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 décembre 2007 23
15 mars 2004 à 17:01
0
hamden79 Messages postés 1 Date d'inscription vendredi 16 avril 2004 Statut Membre Dernière intervention 23 juin 2004
23 juin 2004 à 12:40
déja il fadrais ajouté la réference MicrosoftWord9.0 dans le Com et compilé ton pgm.
voici un code qui te permet d'ouverir d'enregistré sous forme HTML le doc et quitté:

using System;

namespace DocConvert

{
class DoctoRtf
{
static void Main()
{
//Creating the instance of Word Application
Word.Application newApp = new Word.Application();
// specifying the Source & Target file names
object Source="C:\\aahamden\\Word2Html\\Input\\document.doc";
object Target="C:\\aahamden\\Word2Html\\Output\\result.html";
// Use for the parameter whose type are not known or
// say Missing
object o =Type.Missing;
// Source document open here
// Additional Parameters are not known so that are
// set as a missing type
newApp.Documents.Open(ref Source,ref o, ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
// Specifying the format in which you want the output file
object format = Word.WdSaveFormat.wdFormatHTML;
//Changing the format of the document
newApp.ActiveDocument.SaveAs(ref Target,ref format,ref o,ref o,ref o,ref o,ref o,ref o, ref o,ref o,ref o);
// for closing the application
newApp.Quit(ref o,ref o,ref o);
}
}
}
0
Rejoignez-nous