2

I have been trying to separate two numbers using "." but in Excel it sets ",". How can I fix it?

int col= 2;
for (int i = 0; i < proc; i++)
{
       for (int j = 0; j < mac; j++)
    {
       wse.Cells[1, col] = (i + 1).ToString()+"." + (j + 1).ToString();
       col++;
    }
}
Failed Scientist
  • 1,977
  • 3
  • 29
  • 48
Ali Tor
  • 2,772
  • 2
  • 27
  • 58
  • Obviously, it thinks it's a number with decimal fraction you're inserting and replaces the decimal separator to the one prescribed by your culture. Try to prepend the value with an apostrophe (`'`) to make it think it's a string. – ach May 21 '16 at 18:39
  • @AndreyChernyakhovskiy, do you mean `(i + 1) + '.' + (j + 1)`? – Ali Tor May 21 '16 at 18:43
  • 4
    No, I mean `"'" + (i + 1) + "." + (j + 1)`. In Excel, apostrophe is used to let it know that data in a cell is not a number even if it looks like a number. The apostrophe itself won't show up. Note that you don't need to call `ToString()`, that will be called for you automatically when you add strings and things. Or perhaps it might look clearer thus: `String.Format("'{0}.{1}", i + 1, j + 1)`. – ach May 21 '16 at 18:47
  • 2
    Change the columns `NumberFormat` to `"@"`, change the `Application.DecimalSeparator` property or change the culture being used in the assembly. – SierraOscar May 21 '16 at 19:25

0 Answers0