如何读取作为Blob文件存储在Azure存储中的Excel文件

问题描述

我想使用C#中的Epplus包读取作为Blob存储在Azure存储容器中的excel文件。 我试图用这段代码做些事情。

lapply(seq_along(cleanFiles),function(i) 
       writeLines(cleanFiles[[i]],con = file.path(dummyRPath,basename(functionList[i]))))

抛出错误了吗?

解决方法

我们不能使用Azure blob url初始化FileInfo对象,它将引发错误`System.NotSupportedException:'不支持给定路径的格式。'。 enter image description here

因此,如果您想读取存储在Azure blob中的excel文件,我们首先需要下载它。 例如

string connectionString = "";
            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("test");
            BlobClient blobClient = containerClient.GetBlobClient("sample.xlsx");
            
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            using (var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(true)))
            using (ExcelPackage package = new ExcelPackage(stream))
            {
                //get the first worksheet in the workbook
                ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();
                int colCount = worksheet.Dimension.End.Column;  //get Column Count
                int rowCount = worksheet.Dimension.End.Row;     //get row count
                for (int row = 1; row <= rowCount; row++)
                {
                    for (int col = 1; col <= colCount; col++)
                    {
                        Console.WriteLine(" Row:" + row + " column:" + col + " Value:" + worksheet.Cells[row,col].Value.ToString().Trim());
                    }
                }
               
            }




        }

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...