ClosedXML.Report
ClosedXML.Report copied to clipboard
Specified part does not exist in the package
I use closedXML.Report version 0.2.4 for Excel import functionality. It can run normally on some computers, but on some computers it reports an error: Specified part does not exist in the package. Debugging found that it is in Workbook=new XLWorkbook (stream); The exception thrown by this sentence, I don't know what caused it, please help me, thank you.
` public ExcelBuilder<T> LoadFile(IFormFile file) { if (file == null || file.Length == 0) { throw new AppException(GetMessage(ExcelMessage.ImportFileEmpty)); }
if (!file.FileName.Contains(".xls", StringComparison.OrdinalIgnoreCase) ||
!file.FileName.Contains(".xlsx", StringComparison.OrdinalIgnoreCase))
{
throw new AppException(GetMessage(ExcelMessage.ImportFileFormatError));
}
using (var stream = file.OpenReadStream())
{
Workbook = new XLWorkbook(stream);
Worksheet = Workbook.Worksheets.FirstOrDefault();
RowCount = Worksheet.LastRowUsed().RowNumber();
if (Worksheet == null || Worksheet.LastRowUsed().RowNumber() == 0)
{
throw new AppException(GetMessage(ExcelMessage.ImportFileEmpty));
}
}
return this;
}`
@yhdkzy
- can you provide such an EXCEL file where loading fails?
- have you tried to create a local copy of it, opening via Excel (to see if it's corrupted), then making sure no open handle to it exist and then try to open it via
ReadStream?