6 pièce(s) jointe(s)
Access VBA XML XSL Transform
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:
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:
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 |
Access VBA XML XSL Transform
Bonjour,
je viens de lire le message posté ce matin concernant les pièces jointes
je suis désolé, je pensais que les éléments fournis permettaient de mieux comprendre le problème.
merci de me dire si l'exposition de mon problème était clair ou pas
merci pour vos réponses
Cordialement,
Gilbert Pêche
Access VBA XML XSL Transform
bonjour,
merci pour votre réponse
je continue de chercher
Cordialement
G. Pêche
Access VBA XML XSL Transform
Bonjour,
je reviens vers vous car j'ai trouvé comment faire simplement un publipostage dans une macro access en paramétrant l'ouverture de l'état à la place de mon usine à gaz
Mais j'ai un nouveau problème :
quand je veux accéder a l'outil de création d’état, access se mets à ne plus répondre
et là je ne sait plus comment faire
Merci pour vos réponse
Access VBA XML XSL Transform
Bonjour,
il fallait simplement réparer la base de données
Cordialement,
je suis désolé : j'aurais dû essayer de la compacter avant de poser la question
Cordialement,
G.Pêche
Access VBA XML XSL Transform
Bonjour,
je pensais mon problème résolu en réparant et compactant la base, puis en, la sauvegardant, mais le problème revient à chaque fois que je cherche à créer un état, access ne répond plus.
j'ai attendu un certain temps avant de fermer access ou même de faire une fin de tâche mais cela revient à chaque fois
merci pour votre aide
Cordialement
G. Pêche
Access VBA XML XSL Transform
Bonjour,
mon problème est résolu après avoir mis à jour access
Cordialement,
G. Pêche