Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88206

Convert column with mixed data to string

$
0
0

I have an excel file with 1 column, the column contains mixed data,int & string. The column with data


After I read the data from the excel file, I saw that the cell with data AZ-965 is null. this is my string connection

return new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
                                   + excel + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0;';");

and this how I read data from Excel file

private static List<T> GetImportedData<T>(string sheet, OleDbConnection myConnection,
        List<string> column, ImportDataView<T> view) where T : IImportableData
    {
        var cols = string.Join( ",", column.Select(Cast));
        var formattableString = $"select {cols} from [{sheet}$]";
        using (var MyCommand = new 
            OleDbDataAdapter(formattableString, myConnection))
        {
            using (var DtSet = new DataSet())
            {
                int nbRow = 0;
                MyCommand.Fill(DtSet);
                var dt = DtSet.Tables[0];
                var rows = dt.AsEnumerable();
                var convertedList = rows
                    //.AsParallel()
                    .Select(x => GenerateImport<T>(x, column, ref nbRow, view))
                    .ToList();
                return convertedList;
            }
        }
    }

    private static string Cast(string arg)
    {
      return $"IIf(IsNull([{arg}]), '', CStr([{arg}]))";
     // return $"CStr([{arg}]) as {cleanName(arg)}";
     //return $"[{arg}]";
    }

Viewing all articles
Browse latest Browse all 88206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>