阅读asp.net core 1.0上的excel文件 [英] Read an excel file on asp.net core 1.0

查看:151
本文介绍了阅读asp.net core 1.0上的excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我试图在我的asp.net项目上传和读取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.net 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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆