Bonjour,
j'extrais de ma base access les données pour envoyer aux adhérents par courriel des informations concernant leur participation au covoiturage.
il faut envoyer un courriel personnalisé à chaque adhérent et je n'ai pas trouvé la façon de faire avec le publipostage.
le résultat recherché est fourni par la pièce jointe courriel_PECHE_79.txt
l'extraction depuis la base se fait a l'aide d'une macro VBA et de la librairie Microsoft XML 6.0 .
le résultat de cette extraction est un fichier xml (courriel_PECHE_79.xml) suivant le schéma xsd (indemnites.xsd)
pour obtenir le résultat je souhaite utiliser une transformation xslt suivant la feuille de style indemnites_courriel_text.xsl
sur internet j'ai trouvé deux méthodes pour faire cette transformation :
Application.transform
et
l'utilisation de la méthode tramsforme de l'objet MSXML2.DOMDocument60 ?
mais je n'arrive pas à les faire fonctionner.
la première me donne un résultat, mais le fichier obtenu est incorrect (Courriel_VEZO_36.png) à rapprocher de l'encodage du fichier correct fourni par courriel_PECHE_79.png
j'ai tenté d'utiliser un MXXMLWriter60 mais sans succès.
la seconde m'indique un caractère non compris dans le jeu de caractères stipuler pour la transformation
Merci pour vos réponses
Gilbert Pêche
ps le code des macros
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 Sub transform_application() Dim result As New MSXML2.DOMDocument60 'initialisation des variables Dim strPathGP, strPathGV, strPathxslt, strPathResultatGP, strPathResultatGV, strPathResultatGPgp, strPathResultatGVgp As String Dim stylesheet As New MSXML2.DOMDocument60 strPathGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.xml" strPathxslt = "E:\Users\gilbert\marchipontain\ressource\indemnites_courriel_text.xsl" strPathResultatGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.txt" strPathResultatGVgp = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.gp" 'l'opération se fait en 1 ligne ' Application.TransformXML strPath, strPathxslt, strPathResultat 'oXmlDoc.transformNodeToObject stylesheet, result 'result. Application.TransformXML strPathGV, strPathxslt, strPathResultatGVgp Dim iFileNo As Integer iFileNo = FreeFile result.Load strPathResultatGVgp Dim wrt As New MXXMLWriter60 wrt.byteOrderMark = False wrt.omitXMLDeclaration = True wrt.Encoding = "Windows-1252" wrt.indent = False ' Now pass the DOM through the SAX handler, and it will call the writer Dim rdr As New SAXXMLReader60 Set rdr.contentHandler = wrt Set rdr.dtdHandler = wrt Set rdr.errorHandler = wrt rdr.putProperty "http://xml.org/sax/properties/lexical-handler", wrt rdr.putProperty "http://xml.org/sax/properties/declaration-handler", wrt ' Now pass the DOM through the SAX handler, and it will call the writer rdr.parse result ' Let the writer do its thing Open strPathResultatGV For Output As #iFileNo Print #iFileNo, wrt.output Close #iFileNo ' result.Save strPathResultat Set rdr = Nothing Set wrt = Nothing End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub transform_xmldoc() Dim result As New MSXML2.DOMDocument60 Dim oXmlDoc As New MSXML2.DOMDocument60 Dim stylesheet As New MSXML2.DOMDocument60 Dim oerr As Error Dim strPathGP, strPathGV, strPathxslt, strPathResultatGP, strPathResultatGV, strPathResultatGPgp, strPathResultatGVgp As String strPathGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.xml" strPathxslt = "E:\Users\gilbert\marchipontain\ressource\indemnites_courriel_text.xsl" strPathResultatGV = "E:\Users\gilbert\marchipontain\2023-2024\passager_plus_cinq\courriel_VEZO_36.txt" oXmlDoc.Load strPathGV stylesheet.Load "E:\Users\gilbert\marchipontain\ressource\indemnites_courriel_text.xsl" If stylesheet.parseError.errorCode <> 0 Then Set oerr = stylesheet.parseError MsgBox oerr.Description End If If oXmlDoc.parseError.errorCode <> 0 Then Set oerr = oXmlDoc.parseError MsgBox oerr.Description End If oXmlDoc.transformNodeToObject stylesheet, result result.Save strPathResultatGV Set stylesheet = Nothing Set oXmlDoc = Nothing Set result = Nothing End Sub
Partager