Skip to content

Specified part does not exist in the package #396

@yhdkzy

Description

@yhdkzy

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 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;

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions