Bonjour,
j'ai besoin pour mon application de créer un fichier word (.doc) après avoir récolté certaines informations qui doivent être insérée dans ce word.
Après plusieurs heures de recherche sur le net, j'ai trouver un post qui date un peu http://blogs.msdn.com/dotnetinterop/...d-ms-word.aspx. j'ai tester le dans mon programme la méthode ou on utilise le String.replaceAll() et ca marche.
Mais il y a une partie que je ne comprend pas du tout comment faire :
From that starting point, I took 2 paths. The first was to just place within that Template document keywords or fields to be replaced programmatically at runtime, with a simple text replacement library. In Java, the java.lang.String class has a replaceAll() method that accepts regular expressions and inserts replacement text. Easy. I just inserted a set of "fields" that look like ##NAME##. These are not MS-Word "fields", just plain old text, within the XML document, of a well-known format. You can use any format you like. $$NAME$$ if you want, or whatever.
The Java application then populates a Hashtable of name/value pairs, then mechanically replaces all the fields in the doc whose names are present in the Hashtable, with the value of that key. Simple. Find ##FOO## in the doc, and replace that with Hashtable.get("FOO"). The Hashtable can be populated by any means - I inserted the current time of day as one of the name/value pairs, and I also populated the list with data from a SQL query. It could also be populated from a webservices call. Whatever. It's just a Hashtable.
Si je comprend bien, on peu utiliser un HashTable contenant toutes les info que l'on veut remplacer dans le fichier et dont la clé est la même que ce que l'in a mit dans le word entre ##.
Mais je ne vois pas du tout comment faire ca en java.
(Il y a un exemple de mit mais quand j'essaye d'y accéder ca ne marche pas. donc si vous arriver a les avoir ca serait sympas de me les passé.)
Si vous pouviez m'expliquer comment faire ça, ça serait super.
D'avance merci.
Partager