【发布时间】:2020-12-31 05:01:37
【问题描述】:
我的 Blob 存储中有一个 CSV 文件,我需要每天触发它所以我在 azure function app 中使用 timer trigger 我能够获得我的天蓝色函数应用程序中的 CSV 文件数据
-
如何读取和写入 CSV 文件数据 并将其存储在 .xlsx 文件中
-
我是否需要使用绑定我是这个概念的新手,请通过一些示例指导我
我的功能应用:
public static class Function1`
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
try
{
var ConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
// Setup the connection to the storage account
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
// Connect to the blob storage
CloudBlobClient serviceClient = storageAccount.CreateCloudBlobClient();
// Connect to the blob container
CloudBlobContainer container = serviceClient.GetContainerReference("csvfile");
// Connect to the blob file
CloudBlockBlob blob = container.GetBlockBlobReference("empchange.csv");
// Get the blob file as text
string contents = blob.DownloadTextAsync().Result;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
【问题讨论】:
-
CSV 文件每天更新吗?如果是这样,您还可以使用 BlobTrigger,然后您可以使用绑定并为自己节省访问存储帐户、容器和 blob 的额外行。
标签: azure-functions azure-function-app azure-functions-runtime timer-trigger azure-function-async