Formatting numeric cells to culture invariant

Dear All,

I would like to format numeric cell double values so that they preserve the number of decimal digits but use a culture invariant format.

Example: I’d like to format all numbers to this format 123456.789, that is no thousand separators and “.” (dot) as decimal separator. The problem is that I want to preserve the number of decimal digits set in the cell properties window.

Now if I just use Cell.DisplayStringValue then I get the correct number of decimals but I also get the culture dependent thousand and decimal separator caharcters, which I want to avoid.
If I use Cell.DoubleValue I can format the number any way I want, but I have no idea how many decimapl digits shall I use.

How may I get around this problem? Any help is appreciated. Simplest would be to find a culture where there’s no thousand separator characters and use a dot as decimal separator.

Best Regards,
Daniel

Hi,


I could not understand you fully. Please elaborate your query more and give us more details. How could you perform your requirements in MS Excel, give us some steps and screen shots etc. Also provide us a sample Excel file containing your desired formatting manually. We will check it and help you accordingly.

Thank you.

Hi Amjad,

I attached an XLSX with two columns. The first contains cells with double values, the second contains the text string I would like to turn them to. In order to achieve this I need to know how many decimal places the cells in the first column are set up to display.

Best Regards,
Daniel

Hi,


As I could understand your needs a bit (not complete sure though), you may try to use Cell.Value attribute to get the pure data, also you may specify “General” formatting to the cell if you need to apply as per your second column value.

See the sample code for your reference, I used your file as template file.

Sample code:

Workbook wb = new Workbook(“e:\test2\Explanation.xlsx”);
Worksheet sheet = wb.Worksheets[0];
for(int i = 1;i<=sheet.Cells.MaxDataRow; i++)
{
//It will print according to your desired needs
Debug.WriteLine(sheet.Cells[i, 0].Value.ToString());
}

//To format the data, I think you may use General formatting
Style style = wb.CreateStyle();
style.Number = 0;
for (int j = 1; j <= sheet.Cells.MaxDataRow; j++)
{
sheet.Cells[j,0].SetStyle(style);
}

wb.Save(“e:\test2\outputExplanat.xlsx”);

Thank you.