How to upload only non-empty rows of Excel spreadsheet using oledb in C#?

前端 未结 4 1957
遥遥无期
遥遥无期 2021-01-02 07:59

I am importing excel sheet to DataTable using oledb connection as below.

private static DataTable UploadExcelSheet(string fileName)
    {
        DataTable u         


        
4条回答
  •  走了就别回头了
    2021-01-02 08:40

    Expanding on vc's answer, this will remove all rows that which each of it's columns contain either nothing or white space:

    dataTable = dataTable.Rows.Cast().Where(row => !row.ItemArray.All(field => field is System.DBNull || string.Compare((field as string).Trim(), string.Empty) == 0)).CopyToDataTable();
    

提交回复
热议问题