Search code examples
c#.netlinq-to-excel

How to set change Linq to excel Null string values?


I have a model to cast an object list using LINQ to excel.

public class Model{
  public string Name { get; set; }
  public string Date { get; set; }
}

and I am using

var result = excelQueryFactory.Warksheet<Model>(0);

But my excel has Null test in name cells. But they should be empty. So my Name properties filled with Null text. How can I excel these text values while filling the model?


Solution

  • You could add following transformation to your excel factory object:

    excelQueryFactory.AddTransformation<Model>(x => x.Date, cellValue => cellValue??string.Empty);
    excelQueryFactory.AddTransformation<Model>(x => x.Name, cellValue => cellValue??string.Empty);