ClosedXML.Report icon indicating copy to clipboard operation
ClosedXML.Report copied to clipboard

Specified part does not exist in the package

Open yhdkzy opened this issue 6 months ago • 1 comments

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 avatar Aug 22 '25 11:08 yhdkzy

@yhdkzy

  1. can you provide such an EXCEL file where loading fails?
  2. 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?

hidegh avatar Sep 06 '25 12:09 hidegh