I want to keep 'true' and 'false' value as string when I am loading data from CSV file

I want to keep ‘true’ and ‘false’ value as string when I am loading data from CSV file
here is my code in C#:

        var loadOptions  = new Aspose.Cells.LoadOptions(LoadFormat.CSV);
		
    Stream stream = new MemoryStream(fileBytes);
        var workbook = new Workbook(stream, loadOptions);
        var worksheet = workbook.Worksheets[0];

        DataTable dataTable = worksheet.Cells.ExportDataTableAsString(
            0,
            0,
            worksheet.Cells.MaxDataRow + 1,
            worksheet.Cells.MaxDataColumn + 1,
            true);

When I load data from CSV file, I’d like to keep all the data as text. I don’t want my “true” and “false” string converted to TRUE and FALSE.
Could you please help me?

@hosseint,

As I could understand you, I think you want when you load the CSV file into MS Excel, it should not automatically convert “true” value to “TRUE” and “false” value to “FALSE” in the cells. Well, this is MS Excel’s behavior and nothing to do with Aspose.Cells APIs. You may set/apply text formatting to these values (via Aspose.Cells APIs or MS Excel manually) but the bottom line is that those applied formatting would be lost by MS Excel when you save the CSV file.

Could you create your desired CSV file in MS Excel having those Boolean values in tact and provide us here, we will check it on how to do it or retain those values via Aspose.Cells APIs.

Thanks a lot for your response. I upload a zip file contains my test data. Test.zip (156 Bytes)

@hosseint,

Thanks for the file.

As I told you this is MS Excel’s behavior which automatically converts Boolean values to “TRUE” and “FALSE” when opening the file into it, see the screenshot for your reference:

Although the original values are in tact when you open the file into notepad as I confirmed. I actually asked you to provide such a CSV file which should display the Boolean values as “true” and “false”.

@hosseint

You may use the following code for your needs.

C#

private class MyParser : ICustomParser
{
	public object ParseObject(string s)
	{
		return s;
	}


	public string GetFormat()
	{
		return null;
	}
}

//--------------------------------
//--------------------------------

Workbook wb = new Workbook(csvFile, new TxtLoadOptions() 
	{ PreferredParsers = new ICustomParser[] { new MyParser() } });

Many thanks for all of your help. I really appreciate for your quick response.