1
$\begingroup$

I am using linqToExcel to read some .csv files and put in a table.

var excelFile = new LinqToExcel.ExcelQueryFactory(file);

var result = (from row in excelFile.Worksheet(0)
              let item = new IncomingPayments
              {
                  Code = row["Code"].Cast<string>(),
                  Name = row["Name"].Cast<string>(),
                  CustomerCode = row["CustomerCode"].Cast<string>(),
                  Amount = row["Amount"].Cast<double>(),
                  Type = row["Type"].Cast<string>(),                    
              }
              select item).ToList();

An example of the data I am reading:

enter image description here

Problem is that when I get to the rows where the A & B column has a dash, they all return as null. Seems like linqToExcel assumes the colums are int, even when I cast as string. How can I avoid this and get this to work properly?

$\endgroup$
3
  • 1
    $\begingroup$ If you have csv files why not just use something like CsvHelper? $\endgroup$ Commented Jul 20, 2024 at 10:12
  • $\begingroup$ If you cannot define the column types, perhaps a quick fix could be to add an empty space to the end of the value so Excel reads it as a string? $\endgroup$ Commented Jul 20, 2024 at 10:18
  • $\begingroup$ @Guru Stron. I have used that instead. $\endgroup$ Commented Jul 22, 2024 at 6:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.