Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot configure QuoteChar #580

Open
ComeOutToPlay opened this issue Nov 25, 2021 · 1 comment
Open

Cannot configure QuoteChar #580

ComeOutToPlay opened this issue Nov 25, 2021 · 1 comment

Comments

@ComeOutToPlay
Copy link

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.

@andersnm
Copy link
Collaborator

Hi, alas there is no way to configure the quote char in ExcelDataReader currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants