pete87150
Messages postés7Date d'inscriptionvendredi 12 mars 2004StatutMembreDernière intervention24 mars 2004
-
15 mars 2004 à 16:37
hamden79
Messages postés1Date d'inscriptionvendredi 16 avril 2004StatutMembreDernière intervention23 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?)
hamden79
Messages postés1Date d'inscriptionvendredi 16 avril 2004StatutMembreDernière intervention23 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);
}
}
}