我在 SFTP 上有一個 CSV 檔案,它有 13 列,但令人討厭的是最后一個沒有資料或標題,所以基本上每條記錄的末尾都有一個額外的逗號:
PGR,Concession ,Branch ,Branch Name ,Date ,Receipt ,Ref/EAN,Till No ,Qty , Price , Discount , Net Price ,
我想使用邏輯應用程式洗掉最后 13 列并將檔案重新保存在 BLOB 存盤中。我已經從 SFTP 讀取檔案并將整個文本存盤在一個變數中,然后使用 select 只獲取我需要的列,但除此之外我無法弄清楚如何將所有記錄匯出到 1 clean BLOB 中的 csv 檔案。


uj5u.com熱心網友回復:
您需要處理陣列中的每一行并逐個洗掉最后一個逗號。洗掉它時,將結果添加到新的陣列變數中。這是流量的基礎......

這個運算式是主要的作業人員,它將洗掉每一行的最后一個字符......
substring(items('For_each'), 0, add(length(items('For_each')), -1))
前

后

這是邏輯應用程式的定義。把它交給你的租戶,看看它是如何作業的。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "Result String",
"value": "@if(equals(length(items('For_each')), 0), '', concat(substring(items('For_each'), 0, add(length(items('For_each')), -1)), '\r\n'))"
},
"runAfter": {},
"type": "AppendToStringVariable"
}
},
"foreach": "@variables('CSV Data')",
"runAfter": {
"Initialize_Result_String": [
"Succeeded"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Initialize_CSV_Data": {
"inputs": {
"variables": [
{
"name": "CSV Data",
"type": "array",
"value": [
"Header1,Header2,Header3,",
"Test1.1,Test1.2,Test1.3,",
"Test2.1,Test2.2,Test2.3,",
"",
"Test3.1,Test3.2,Test3.3,",
""
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Cleansed_CSV_Data": {
"inputs": {
"variables": [
{
"name": "Cleansed CSV Data",
"type": "array"
}
]
},
"runAfter": {
"Initialize_CSV_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Result_String": {
"inputs": {
"variables": [
{
"name": "Result String",
"type": "string"
}
]
},
"runAfter": {
"Initialize_Cleansed_CSV_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Result",
"type": "string",
"value": "@variables('Result String')"
}
]
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Month",
"interval": 3
},
"recurrence": {
"frequency": "Month",
"interval": 3
},
"type": "Recurrence"
}
}
},
"parameters": {}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443916.html
