I have a CSV file in my Blob Storage and I need to trigger it every day So I am using timer trigger in azure function app I am able to get the Csv file Data in my azure function-app
how to read and write the CSV-file data and store it in .xlsx file
should I need to Use bindings I am new to this Concept please guide me on this with some Examples
My function App:
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);
}
}
}
If you want to read and write CSV files, you need to install
CsvHelper
NuGet.CsvHelper
has many examples for you to learn how to read and write csv files. I wrote a code sample for reading csv files for you.Excel Data
Code Sample
As for converting the csv file into
.xlsx
file, I saw this post, it should be able to solve your problem.You can use binding, but your approach can achieve the same purpose. I don't think you need to change your approach. You can learn Binding concept from the official document.