dotnetcore / Magicodes.IE

Import and export general library, support Dto import and export, template export, fancy export and dynamic export, support Excel, Csv, Word, Pdf and Html.
http://docs.dotnet-china.com/Magicodes.IE
MIT License
2.1k stars 481 forks source link

空指针异常 #549

Open Farb opened 9 months ago

Farb commented 9 months ago

Expected behaviour

即使缺少列名,也不应该报错空指针,而应该给出具体的错误。当前不使用源码调试的话,根本不知道哪里的问题

Actual behaviour

image

Tell us what happens instead. Provide a log message if relevant. 导入excel时,实体类的字段在excel中少一个字段

I'm seeing this behaviour on

package versions

PackageReference Include="Magicodes.IE.Excel" Version="2.7.4.5"

So how can we reproduce this?

导入excel时,实体类的字段在excel中少一个字段

Awesome :star::star::star::star::star:

Provide a (link to a) minimal demo app showing the faulty behaviour.

Sweet :star::star::star::star:

Provide a concise code sample which can upload attachments. 将var filePath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import", "班级学生基础数据导入.xlsx"); 文件sheet中的第一个列删除,然后运行以下测试用例即可复现。

      [Fact(DisplayName = "班级学生基础数据导入")]
      public async Task ClassStudentInfoImporter_Test()
      {
          var filePath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import", "班级学生基础数据导入.xlsx");
          var importDic = await Importer.ImportSameSheets<ImportClassStudentDto, ImportStudentDto>(filePath);
          foreach (var item in importDic)
          {
              var import = item.Value;
              import.ShouldNotBeNull();
              if (import.Exception != null) _testOutputHelper.WriteLine(import.Exception.ToString());
              if (import.RowErrors.Count > 0)
                  _testOutputHelper.WriteLine(JsonConvert.SerializeObject(import.RowErrors));
              import.HasError.ShouldBeFalse();
              import.Data.ShouldNotBeNull();
              import.Data.Count.ShouldBe(16);
          }
      }

Good :star::star::star:

Provide your own app and instructions how to reproduce the issue.

Meh :star::star:

Provide a code sample with a bunch of magic parameters which I need to interpolate by guessing to reconstruct the actual runtime code.

Worst :poop:

Say the source code can't be disclosed and refuse to provide any of the above. Expect this issue to be closed by a bunch of angry aliens :alien::alien::alien::alien::alien: that will hunt you down and :fire: your :computer:. You've been warned. :fire_engine: