I need to develop azure function for read Excel file row by row and insert those data in to database
so by using below code i was able to get file from HTTP request
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
{
var excel_file = req.Form.Files["file"];
// read file and insert data and to database
return excel_file != null
? (ActionResult)new OkObjectResult(excel_file)
: new BadRequestObjectResult("err..");
}
i saw there are many ways to read excel sheet in c# such as
Microsoft.Office.Interop.Excel
ExcelMapper
OLEDB ..etc
but the problem is those are need the file stored path
problem is can i read these excel file without writing in a blob or other location
Thank you
You can try ExcelDataReader , using stream as input parameter. Assuming that excel_file
is byte array you can use code bellow:
using (var stream = new MemoryStream(excel_file))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
while (reader.Read())
{
for (var i = 0; i < reader.FieldCount; i++)
{
var value = reader.GetValue(i)?.ToString();
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.