VB.net code read an excel content from blob

Posted by Rajnilari2015 under Azure category on | Points: 40 | Views : 2066
The below code will do so

Public Function GetExcelBlobData(filename As String, connectionString As String, containerName As String) As DataSet
' Retrieve storage account from connection string.
Dim storageAccount As CloudStorageAccount = CloudStorageAccount.Parse(connectionString)

' Create the blob client.
Dim blobClient As CloudBlobClient = storageAccount.CreateCloudBlobClient()

' Retrieve reference to a previously created container.
Dim container As CloudBlobContainer = blobClient.GetContainerReference(containerName)

' Retrieve reference to a blob named "myblob.csv"
Dim blockBlob2 As CloudBlockBlob = container.GetBlockBlobReference(filename)

Dim ds As DataSet
Using memoryStream = New MemoryStream()
' used third party open source Excel Data Reader - Read Excel files in .NET(http://exceldatareader.codeplex.com/)
' Nuget: Install-Package ExcelDataReader (https://www.nuget.org/packages/ExcelDataReader/)

Dim excelReader = ExcelReaderFactory.CreateOpenXmlReader(memoryStream)
ds = excelReader.AsDataSet()
End Using

Return ds
End Function

Comments or Responses

Login to post response