我已经开始工作了,但它已经停止了,我不明白为什么。我正在使用 EPPlus.Core v1.3 导入一个简单的 excel 文件。这是我正在使用的代码:
public async Task<IActionResult> Import(IFormFile file)
{
//Get file
var newfile = new FileInfo(file.FileName);
var fileExtension = newfile.Extension;
//Check if file is an Excel File
if (fileExtension.Contains(".xls"))
{
//Create an excel package
using (var package = new ExcelPackage(newfile))
{
//Get the first worksheet in the file
var worksheet = package.Workbook.Worksheets[1];
...
var 工作表行抛出错误
"IndexOutOfRangeException: Worksheet position out of range."
但是,当我查看包变量时,我看到了这个错误
"Length = 'package.File.Length' threw an exception of type 'System.IO.FileNotFoundException'"
我在这里错过了什么?就像我说的,这曾经有效,我想不出与此代码相关的任何更改会导致此问题。
最佳答案
这也是同一个文件吗?看起来该文件可能没有两个工作表,并且由于索引为 1,它正在寻找第二个工作表。
关于c# - Asp.net Core 导入Excel文件FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42583013/