Skip to content

Cannot configure QuoteChar #580

Description

@ComeOutToPlay

I have a file tab separated and one of the cell values is a double quote ("). When I read the row using the reader, it understand it is a longer value. My test code is as follows:

using System;
using System.Collections.Generic;
using System.IO;
using ExcelDataReader;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

            ExcelReaderConfiguration excelReaderConfiguration = new ExcelReaderConfiguration()
            {
                // Remember default value is autodetect with new char[] { ',', ';', '\t', '|', '#' }
                // https://github.com/ExcelDataReader/ExcelDataReader
                AutodetectSeparators = new char[] { '\t' },
            };

            using (var stream = File.Open("C:\\quote.csv", FileMode.Open, FileAccess.Read))
            {
                using var reader = ExcelReaderFactory.CreateCsvReader(stream, excelReaderConfiguration);

                List<object> list = new();

                while (reader.Read())
                {

                    List<object> valList = new();
                    int fields = reader.FieldCount;


                    for (int i = 0; i < fields; i++)
                    {
                        string readValue = reader.GetString(i);

                        valList.Add(readValue);

                        if (i==7) Console.WriteLine($"Row value at index 7 is: {readValue}");
                    }

                    list.Add(valList);
                }
            }
        }
    }
}

The "quote.csv" file I used is the following:

	Rol	  ID	Objeto	Autoriz.	Variante	Nom.campo	Valor	Y	Status del objeto	Indica, si objeto es borrado	Indica, si objeto es copiado	Indica, si el objeto es nuevo	 ID
	D_GLB_MM_LIBE-PEDI-ANAPUR	   3	C_KLAH_BKL	DGLBMMLPAC00		ACTVT	02		G			O	  9
	D_GLB_MM_LIBE-PEDI-ANAPUR	   4	C_KLAH_BKL	DGLBMMLPAC00		BGRKL	"		G			O	 10
	D_GLB_MM_LIBE-PEDI-ANAPUR	   5	C_TCLA_BKA	DGLBMMLPAC00		KLART			S			O	 13

I found in the code that the QuoteChar is a private variable with value '"'. Do you know a way of parsing correctly the row containing a double quote?

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions