Save as SaveFormat.CVS not retainig actual value

I want to be able to save any excel file to csv without having to manipulate the format of specific cells. This is what I am doing to save the file:

Workbook wb = new Workbook(file.InputStream);
wb.Save(ConvertedFilePath, SaveFormat.CSV);

For the most part it saves the file as I want but some files have formatting applied and the resulting csv does not preserve the actual data. For example:

The actual values of are
1/1/3001
1/1/2101
but the file has some formatting applied and it displays as the following:
Jan-01
Jan-01

When converting to CSV I want the values 1/1/3001 and 1/1/2101 but instead I am getting the formatted values.

Is there a setting I can apply to the entire workbook so that it converts with the actual values?

Attached is a sample file if you need it.

Thanks in advance.




Hi,

Thanks for your posting and using Aspose.Cells.

There are two ways to deal with this problem.

1 - Access Style of all the cells inside all the worksheets of your workbook and change them to your desired date format

2 - Access all the styles of the workbook using the Workbook.GetStyleInPool() method and change the date formats.

Please see the 2nd method which is more efficient. I have also attached the output csv for your reference.

C#
Workbook workbook = new Workbook(“Dates.xlsx”);

//Please access all of your styles and change some of them as you need
//Observe the properties in debugging and then change them.
for(int i=0; i< workbook.CountOfStylesInPool; i++)
{
Style style = workbook.GetStyleInPool(i);

Debug.WriteLine(i + “-Number-” + style.Number);
Debug.WriteLine(i + “-Custom-” + style.Custom);
Debug.WriteLine(i + “-Culture-” + style.CultureCustom);

//Since we only want to change this one
if(style.CultureCustom == “MMM-yy”)
{
style.CultureCustom = “dd/MM/yyyy”;
}
}

workbook.Save(“output.csv”);