I am using the following code-

 private static HashSet<string> keepHeaders = new HashSet<string>{
     "Screen", "Section", "Question Name", "Question Label", 
     "Question Type", "Required?", "Choice Group", 
     "Min", "Max", "Max Length", "Label", "Choice Label", 
     "Name", "Description" 
 };

 private static string ExtractDataCatalogAlt(IFormFile file)
 {
     Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
      using (var excelStream = file.OpenReadStream())
      using (var reader = ExcelReaderFactory.CreateOpenXmlReader(excelStream, new ExcelReaderConfiguration { FallbackEncoding = Encoding.GetEncoding(1252) }))
     {
         var headers = new List<string>();
         var dataSet = reader.AsDataSet(new ExcelDataSetConfiguration
         {
             ConfigureDataTable = (_) => new ExcelDataTableConfiguration
             { 
                 UseHeaderRow = true,
                 ReadHeaderRow = (r) =>
                 {
                     // store the header row values so we can trim columns out that don't have headers
                     for (var i = 0; i < r.FieldCount; i++)
                            headers.Add(r.GetString(i));
                 },
                 FilterColumn = (_, c) =>
                 {
                     return keepHeaders.Contains(headers[c]);  
                 }
                }
         });

         return JsonConvert.SerializeObject(dataSet, Formatting.Indented);
     }
 }

Can you tell what condition should I put in FilterColumn so that it reads only cells which has values and not give output as "column6" : null

0

There are 0 answers