你好我真的试图上传和我的asp.net项目中读取Excel文件,但所有我找到的文档是ASP MVC 5. 我的目标是读Excel表格并将值传递给对象列表。阅读一个Excel的asp.net核心文件1.0
这是我的控制器,它的工作文件上传到我的wwwroot /上传
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();
}
EPPlus不支持.NET的核心,但有一个名为EPPlus库的非官方端口EPPlus.core可以用来读写excel。看到这个[链接](http://www.talkingdotnet.com/import-export-xlsx-asp-net-core/) – VirendraJ
我会说这很重要,特别是如果你正在尝试读取xls或密码保护的Excel文件。大多数软件包使用折旧的数据结构,例如未在Core中实现的datatables或ole连接提供程序。密码保护的文件也需要用于读/写操作的Office com库。 – schwietertj