Conversion d'une macro VBA vers Google Apps Script
y
Bonjour à tous,
Tout d'abord je remercie par avance toutes les personnes qui vont s'intéresser au sujet et essayer d'y apporter une réponse ou des conseils je suis preneur.
Je suis entrain de convertir des Macros VBA en Script sur Google Sheets, ma macro VBA est un appel d'API permettant de récupérer des données renvoyées en format JSON , je souhaiterais convertir une partie de mon code en version APP script, et étant encore novice sur sheets, je ne trouve pas forcément d'équivalence, auriez-vous des idées ou conseils svp ?
ci-dessous mon bout de code à passer sur APP SCRIPT :
'Récupération des infos deSet taxeTableauTaxesInclusion incluses= ouNew pasDictionary
If Not IsEmpty(Produit("leclercTaxInclusionInformationList")) Then
For t = 1 To Produit("leclercTaxInclusionInformationList").Count 'Parcours des taxes incluses
Set UneTaxe = Produit("leclercTaxInclusionInformationList").Item(t)
If Not IsEmpty(UneTaxe("leclercTaxCode")) And Not IsNull(UneTaxe("leclercTaxCode")) Then
TableauTaxesInclusion.Add UneTaxe("leclercTaxCode")("code"), IIf(Not IsEmpty(UneTaxe("leclercIsTaxIncludedInPrice")) And Not IsNull(UneTaxe("leclercIsTaxIncludedInPrice")) And UneTaxe("leclercIsTaxIncludedInPrice") = True, "X", "")
'Debug.Print UneTaxe("leclercTaxCode")("code")
End If
Next
End If
Next
End If
If Not IsEmpty(Produit("dutyFeeTaxInformationList")) Then
Set TableauTaxes = New Dictionary
For t = 1 To Produit("dutyFeeTaxInformationList").Count
Set Taxe = Produit("dutyFeeTaxInformationList")(t)
If Not (IsNull(Taxe("dutyFeeTaxTypeCode"))) Then
If NotIf (IsNullTableauTaxes.Exists(Taxe("dutyFeeTaxTypeCode")("code")) Then
TableauTaxes(Taxe("dutyFeeTaxTypeCode")("code")) = 1 + TableauTaxes(Taxe("dutyFeeTaxTypeCode")("code"))
If Else
TableauTaxes.Exists(Add Taxe("dutyFeeTaxTypeCode")("code"), 1
End If
End If
Next
For t = 1 To Produit("dutyFeeTaxInformationList").Count Then'Parcours des taxes
Set Taxe = Produit("dutyFeeTaxInformationList")(t)
If Not (IsNull(Taxe("dutyFeeTaxTypeCode"))) Then
TableauTaxesIf Left(Taxe("dutyFeeTaxTypeCode")("code""label"), 3) = 1"TVA" +Or TableauTaxesLeft(Taxe("dutyFeeTaxTypeCode")("code""label"), 3) = "VAT" Then
If tva = True Then
Else
TableauProduits(ligne, numColCheckTVA) = "X"
If TableauTaxes.AddTableauProduits(ligne, numColTVA) = Taxe("dutyFeeTaxTypeCode")("code""label") Then
If TableauProduits(ligne, 1numColValTVA) = "" Then
If (Taxe("dutyFeeTaxList").Count > 0) Then
TableauProduits(ligne, numColValTVA) = Taxe("dutyFeeTaxList")(1)("dutyFeeTaxRateNumber")
End If
End If
Next
For t = 1 To Produit("dutyFeeTaxInformationList").Count 'Parcours des taxes
Set Taxe = Produit("dutyFeeTaxInformationList")(t)
If Not (IsNull(Taxe("dutyFeeTaxTypeCode"))) Then
If Left(Taxe("dutyFeeTaxTypeCode")("label"), 3) = "TVA" Or Left(Taxe("dutyFeeTaxTypeCode")("label"), 3) = "VAT" Then
If tva = True Then
TableauProduits(ligne, numColCheckTVA) = "X"
If TableauProduits(ligne, numColTVA) = Taxe("dutyFeeTaxTypeCode")("label") Then
If TableauProduits(ligne, numColValTVA) = "" Then
If (Taxe("dutyFeeTaxList").Count > 0) Then
TableauProduits(ligne, numColValTVA) = Taxe("dutyFeeTaxList")(1)("dutyFeeTaxRateNumber")
End If
End If
Else
TableauProduits(ligne, numColCheckTVA) = "PB"
End If
Else
TableauProduits(ligne, numColTVA) = Taxe("dutyFeeTaxTypeCode")("label")
If (Taxe("dutyFeeTaxList").Count > 0) Then
TableauProduits(ligne, numColValTVA) = Taxe("dutyFeeTaxList")(1)("dutyFeeTaxRateNumber")
If (Taxe("dutyFeeTaxList").Count > 1) Then
TableauProduits(ligne, numColCheckTVA) = "PB"
End If
End If
End If
tva = True
If Not IsNull(Taxe("dutyFeeTaxEffectiveStartDate")) Then TableauProduits(ligne, numColTVA + 3) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveStartDate")))
If Not IsNull(Taxe("dutyFeeTaxEffectiveEndDate")) Then TableauProduits(ligne, numColTVA + 4) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveEndDate")))
Else
TableauProduits(ligne, coltaxe) = Taxe("dutyFeeTaxTypeCode")("label")
If Not IsNull(Taxe("dutyFeeTaxEffectiveStartDate")) Then TableauProduits(ligne, coltaxe + 4) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveStartDate")))
If Not IsNull(Taxe("dutyFeeTaxEffectiveEndDate")) Then TableauProduits(ligne, coltaxe + 5) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveEndDate")))
If TableauTaxesInclusion.Exists(Taxe("dutyFeeTaxTypeCode")("code")) Then TableauProduits(ligne, coltaxe + 6) = TableauTaxesInclusion(Taxe("dutyFeeTaxTypeCode")("code"))
If TableauTaxes(Taxe("dutyFeeTaxTypeCode")("code")) > 1 Then
TableauProduits(ligne, coltaxe + 3) = "X"
End If
For u = 1 To Taxe("dutyFeeTaxList").Count
If Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count > 0 Then
For v = 1 To Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count
Set UneTaxe = Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber")(v)
TableauProduits(ligne, coltaxe + 1) = UneTaxe("expressedIn")("code")
TableauProduits(ligne, coltaxe + 2) = UneTaxe("data")
Next
End If
Next
coltaxe = coltaxe + 7
End If
Else
TableauProduits(ligne, coltaxe) = "<NULL>"
If Not IsNull(Taxe("dutyFeeTaxEffectiveStartDate")) Then TableauProduits(ligne, coltaxe + 4) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveStartDate")))
If Not IsNull(Taxe("dutyFeeTaxEffectiveEndDate")) Then TableauProduits(ligne, coltaxe + 5) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveEndDate")))
For u = 1 To Taxe("dutyFeeTaxList").Count
If Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count > 0 Then
For v = 1 To Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count
Set UneTaxe = Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber")(v)
TableauProduits(ligne, coltaxe + 1) = UneTaxe("expressedIn")("code")
TableauProduits(ligne, coltaxe + 2) = UneTaxe("data")
Next
End If
Next
coltaxe = coltaxe + 7
End If
End If
End If
On Error GoTo 0 tva = True
NextIf Not IsNull(Taxe("dutyFeeTaxEffectiveStartDate")) Then TableauProduits(ligne, numColTVA + 3) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveStartDate")))
End If Not IsNull(Taxe("dutyFeeTaxEffectiveEndDate")) Then TableauProduits(ligne, numColTVA + 4) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveEndDate")))
Else
TableauProduits(ligne, coltaxe) = Taxe("dutyFeeTaxTypeCode")("label")
If Not IsMissingIsNull(TableauCurrProduitTaxe("dutyFeeTaxEffectiveStartDate")) Then TableauProduits(ligne, coltaxe + 4) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveStartDate")))
ForIf iNot IsNull(Taxe("dutyFeeTaxEffectiveEndDate")) Then TableauProduits(ligne, coltaxe + 5) = LBoundUnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveEndDate")))
If TableauTaxesInclusion.Exists(Taxe("dutyFeeTaxTypeCode")("code")) Then TableauProduits(ligne, 2coltaxe + 6) To= UBoundTableauTaxesInclusion(Taxe("dutyFeeTaxTypeCode")("code"))
If TableauTaxes(Taxe("dutyFeeTaxTypeCode")("code")) > 1 Then
TableauProduits(ligne, 2coltaxe + 3) = "X"
End If
TableauCurrProduit For u = 1 To Taxe("dutyFeeTaxList").Count
If Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count > 0 Then
For v = 1 To Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count
Set UneTaxe = Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber")(v)
TableauProduits(ligne, icoltaxe + 1) = UneTaxe("expressedIn")("code")
TableauProduits(ligne, icoltaxe + 2) = UneTaxe("data")
Next
End If
Next
coltaxe = coltaxe + 7
End If
Else
TableauProduits(ligne, coltaxe) = "<NULL>"
If Not IsNull(Taxe("dutyFeeTaxEffectiveStartDate")) Then TableauProduits(ligne, coltaxe + 4) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveStartDate")))
If Not IsNull(Taxe("dutyFeeTaxEffectiveEndDate")) Then TableauProduits(ligne, coltaxe + 5) = UnixTimeStamp2Date(CLng(Taxe("dutyFeeTaxEffectiveEndDate")))
For u = 1 To Taxe("dutyFeeTaxList").Count
If Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count > 0 Then
For v = 1 To Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber").Count
Set UneTaxe = Taxe("dutyFeeTaxList")(u)("dutyFeeTaxAmountNumber")(v)
TableauProduits(ligne, coltaxe + 1) = UneTaxe("expressedIn")("code")
TableauProduits(ligne, coltaxe + 2) = UneTaxe("data")
Next
End If
Next
coltaxe = coltaxe + 7
End If
On Error GoTo 0
Next
End If
If Not IsMissing(TableauCurrProduit) Then
For i = LBound(TableauProduits, 2) To UBound(TableauProduits, 2)
TableauCurrProduit(0, i) = TableauProduits(ligne, i)
Next
End If
ligne = ligne + 1
End If