阅读asp.net core 1.0上的excel文件

编程入门 行业动态 更新时间:2024-10-25 21:26:41
本文介绍了阅读asp core 1.0上的excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我试图在我的asp项目上传和读取excel文件,但我找到的所有文档都是针对ASP MVC 5. 我的目标是阅读excel表并将值传递给一个对象列表。

这是我的控制器,它适用于将文件上传到我的wwwroot / uploads

public class HomeController:Controller { private IHostingEnvironment _environment; public HomeController(IHostingEnvironment environment) { _environment = environment; } public IActionResult index() { return View(); } [HttpPost] 公共异步任务< IActionResult>索引(ICollection< IFormFile>文件) { var uploads = Path.Combine(_environment.WebRootPath,uploads); foreach(文件中的var文件) { if(file.Length> 0) { using(var fileStream = new FileStream(Path.Combine( uploads,file.FileName),FileMode.Create)) { await file.CopyToAsync(fileStream); } } } 返回View(); }

解决方案

在.NET Core OleDb中DataTables消失了。这使得某些项目难以将自己移植到netcore。

如果您正在阅读OpenXml Excel文件(xlsx),非官方的Epplus.Core可以帮助您。 / p>

但是对于较旧的97-2003格式(xls),我们还找不到解决方案。

I希望NPOI或ExcelDataReader能够在今年晚些时候获得核心版本,但我没有看到很多活动。

Hello I`m trying to upload and read an excel file on my asp project but all the documentation I find is for ASP MVC 5. My goal is to read the excel sheet and pass the values to an list of objects.

This is my controller, it works for upload the file to my wwwroot/uploads

public class HomeController : Controller { private IHostingEnvironment _environment; public HomeController(IHostingEnvironment environment) { _environment = environment; } public IActionResult index() { return View(); } [HttpPost] public async Task<IActionResult> Index(ICollection<IFormFile> files) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); foreach (var file in files) { if (file.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } } return View(); }

解决方案

In .NET Core OleDb and DataTables are gone. This makes it harder for some projects to port themselves to netcore.

If you're reading OpenXml Excel files (xlsx), the unofficial Epplus.Core can help you.

But for the older 97-2003 formats (xls) we couldn't find a solution yet.

I would hope either NPOI or ExcelDataReader would get a core version later this year, but i don't see much activity on that direction.

更多推荐

阅读asp.net core 1.0上的excel文件

本文发布于:2023-11-05 07:25:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   net   asp   core   excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!