2

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

Flydog57
  • 6,851
  • 2
  • 17
  • 18
jo_Veera
  • 293
  • 3
  • 12
  • In the Excel file, What happens if you press `+G`, choose `Special` and select `Last Cell`. Excel will remember what the last cell you have worked in, even if it's now unused. If you delete the offending column (select the column, choose Delete and Column from the button bar), then save the file, close it and re-open it, the last cell will now be set properly – Flydog57 Apr 22 '22 at 20:59
  • Thanks for your suggestion. But There will be many excel files getting generated and everytime the user would have to open the excel file and update the last cell. – jo_Veera Apr 25 '22 at 06:47

0 Answers0