>>>>>>>>>>>>>>>>>>>>
namespace WordAutomation
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Fusion
{
public static string START_PATTERN = "<<";
public static string END_PATTERN = ">>";
/// <summary>
/// The fusion entry point for the application.
/// </summary>
[STAThread]
public static void MergeDocument(Hashtable h, string inDoc, string
outDoc)
{
// Déclaration des variables automation
object FileSave = (object)outDoc;
object WordFormat = 1;
object missing = System.Reflection.Missing.Value;
object modelAdress = inDoc;
object newTemplate = false;
object oFalse = false;
object docType = 0;
object isVisible = true;
object o = Missing.Value;
string currentWord, currentKey;
object saveChanges = false;
Word.ApplicationClass WordApp = new Word.ApplicationClass();
Word.Document aDoc = WordApp.Documents.Add(ref modelAdress, ref
newTemplate, ref missing, ref oFalse);
IEnumerator ie = aDoc.Words.GetEnumerator();
// Visibilité du document
WordApp.Visible = false;
// Activation du document
aDoc.Activate();
while (ie.MoveNext())
{
// After word replace, it can still exists END_PATTERN,
remove it.
currentWord = ((Word.Range)ie.Current).Text;
if (currentWord.StartsWith(START_PATTERN))
{
// Remove "<<" pattern
((Word.Range)ie.Current).Delete(ref missing, ref missing);
ie.MoveNext();
currentKey = ((Word.Range)ie.Current).Text;
// Remove key pattern
((Word.Range)ie.Current).Delete(ref missing, ref missing);
// Replace by value string in hashtable
((Word.Range)ie.Current).InsertAfter(h[currentKey].ToString());
// Remove ">>" pattern
ie.MoveNext(); ie.MoveNext();
// Remove ">>" pattern
((Word.Range)ie.Current).Text =
((Word.Range)ie.Current).Text.Replace(END_PATTERN, "");
}
if (currentWord.StartsWith(END_PATTERN))
((Word.Range)ie.Current).Text =
((Word.Range)ie.Current).Text.Replace(END_PATTERN, "");
}
// Sauvegarde du document
aDoc.SaveAs2000(ref FileSave, ref WordFormat, ref oFalse, ref
missing, ref oFalse, ref missing, ref oFalse, ref oFalse, ref oFalse, ref
oFalse, ref oFalse);
// Désallocation des ressources
saveChanges = false;
aDoc.Close(ref saveChanges, ref missing, ref missing);
WordApp.Quit(ref saveChanges, ref missing, ref missing);
WordApp = null;
}
public static void Main()
{
Hashtable h = new Hashtable();
// La source de données ici est une hashtable codée en dur
h.Add("Civilite", "Mr");
h.Add("Nom", "GIL");
h.Add("Prenom", "Thomas");
h.Add("Date", DateTime.Now);
// Appel la fusion en précisant le document modèle et le
document généré
MergeDocument(h, "c:\\modele.dot", "c:\\generated.doc");
}
}
}
>>>>>>>>>>>>>>maintenant faut y faire appel depuis un bouton et je ne trouve pas la syntaxe online
voila j'espere avoir eté claire et bien informative pour que vous puissiez
m'aidé
encore merci ;-)
Après tu appels les méthodes et tu instancies les objets comme si ils
étaient dans le namespace de ton application Web.
Oui, ton application Web crée aussi un namespace ;-).
--
Paul Bacelar
MVP VC++
"nima84" <nim...@discussions.microsoft.com> wrote in message
news:F65760B4-8F51-4FF8...@microsoft.com...