Azure 逻辑应用程序可以从存储帐户读取 excel 文件吗?
Can an Azure Logic App read an excel file from a storage account?
我有一个 excel 电子表格驻留在 Azure 存储帐户的容器中。
我可以使用带有“获取 Blob 内容”的 Azure 逻辑应用来访问该文件。但是我找不到任何讨论实际从 blob 存储中读取 Azure 逻辑应用程序中的文件的文档。请注意,OneDrive 或 Office365 中有用于访问 Excel 文件的连接器,但存储帐户容器中没有。
尽管进行了激烈的搜索,但我没有在 Microsoft 文档或其他地方找到任何关于此用例的讨论。任何链接将不胜感激。
从 Blob 存储 read/search Azure 逻辑应用程序中的 excel 文件的最佳方法是什么?
您可以将 Azure Functions 添加到您的工作流中并轻松读取电子表格的内容:
public class ExcelFileContentExtractorService : IExcelFileContentExtractorService
{
public ExcelFileRawDataModel GetFileContent(Stream fileStream)
{
IDictionary<string, string> cellValues = new Dictionary<string, string>();
IWorkbook workbook = WorkbookFactory.Create(fileStream);
ISheet reportSheet = workbook.GetSheetAt(0);
if (reportSheet != null)
{
int rowCount = reportSheet.LastRowNum + 1;
for (int i = 0; i < rowCount; i++)
{
IRow row = reportSheet.GetRow(i);
if (row != null)
{
foreach (var cell in row.Cells)
{
var cellValue = cell.GetFormattedCellValue();
if (!string.IsNullOrEmpty(cellValue))
{
cellValues.Add(cell.Address.FormatAsString(), cellValue);
}
}
}
}
}
return new ExcelFileRawDataModel()
{
Id = cellValues["A6"],
CarBrand = cellValues["B6"],
CarModel = cellValues["C6"],
CarPrice = decimal.Parse(cellValues["D6"]),
CarAvailability = int.Parse(cellValues["E6"])
};
}
}
我尝试用 CSV 做同样的事情,但没有取得太大进展。根据我的经验,尝试解析文件内容很笨拙。有一些用于逻辑应用程序的第 3 方插件(连接器),但我不愿意使用它们,因为我相信数据是作为处理的一部分发送到第 3 方站点的。如果您的数据不是特别敏感,您可以尝试这些连接器。
这里我会补充我所学的。
尽管在撰写本文时本机支持从 OneDrive 和 Sharepoint 读取 excel 文件,但 Microsoft 产品经理不知何故错过了 Azure 客户可能希望使用 Azure 从 Azure(存储帐户 blob)中读取他们的内容Logic Apps 等工具。
撰写本文时唯一的解决方案是创建一个生成 SAS 令牌并读取 blob 的 Azure 函数。
因此,我将 Thiago 的回复标记为正确。
我有一个 excel 电子表格驻留在 Azure 存储帐户的容器中。
我可以使用带有“获取 Blob 内容”的 Azure 逻辑应用来访问该文件。但是我找不到任何讨论实际从 blob 存储中读取 Azure 逻辑应用程序中的文件的文档。请注意,OneDrive 或 Office365 中有用于访问 Excel 文件的连接器,但存储帐户容器中没有。
尽管进行了激烈的搜索,但我没有在 Microsoft 文档或其他地方找到任何关于此用例的讨论。任何链接将不胜感激。
从 Blob 存储 read/search Azure 逻辑应用程序中的 excel 文件的最佳方法是什么?
您可以将 Azure Functions 添加到您的工作流中并轻松读取电子表格的内容:
public class ExcelFileContentExtractorService : IExcelFileContentExtractorService
{
public ExcelFileRawDataModel GetFileContent(Stream fileStream)
{
IDictionary<string, string> cellValues = new Dictionary<string, string>();
IWorkbook workbook = WorkbookFactory.Create(fileStream);
ISheet reportSheet = workbook.GetSheetAt(0);
if (reportSheet != null)
{
int rowCount = reportSheet.LastRowNum + 1;
for (int i = 0; i < rowCount; i++)
{
IRow row = reportSheet.GetRow(i);
if (row != null)
{
foreach (var cell in row.Cells)
{
var cellValue = cell.GetFormattedCellValue();
if (!string.IsNullOrEmpty(cellValue))
{
cellValues.Add(cell.Address.FormatAsString(), cellValue);
}
}
}
}
}
return new ExcelFileRawDataModel()
{
Id = cellValues["A6"],
CarBrand = cellValues["B6"],
CarModel = cellValues["C6"],
CarPrice = decimal.Parse(cellValues["D6"]),
CarAvailability = int.Parse(cellValues["E6"])
};
}
}
我尝试用 CSV 做同样的事情,但没有取得太大进展。根据我的经验,尝试解析文件内容很笨拙。有一些用于逻辑应用程序的第 3 方插件(连接器),但我不愿意使用它们,因为我相信数据是作为处理的一部分发送到第 3 方站点的。如果您的数据不是特别敏感,您可以尝试这些连接器。
这里我会补充我所学的。
尽管在撰写本文时本机支持从 OneDrive 和 Sharepoint 读取 excel 文件,但 Microsoft 产品经理不知何故错过了 Azure 客户可能希望使用 Azure 从 Azure(存储帐户 blob)中读取他们的内容Logic Apps 等工具。
撰写本文时唯一的解决方案是创建一个生成 SAS 令牌并读取 blob 的 Azure 函数。
因此,我将 Thiago 的回复标记为正确。