我使用EPPlus生成的文件在不同的PC上获得不同的数字

我在我的C#应用​​程序中使用EPPlus生成Excel文件的代码,一切正常,我发送应用程序到客户端,他说,它显示错误的数字。 在他寄给我的Excel文件中,数字真的不一样。 无法弄清楚为什么。 我怀疑Excel是罪魁祸首,因为区域设置或类似的东西而不同地解释数字。 我怎样才能解决这个问题? 例如,20在另一台PC上变成2000:

Decimal.TryParse(dataGridView1.Rows[e.RowIndex].Cells[15].Value.ToString().Replace(".", ","), out number); //cell value 20.00 ws.Cells["I33"].Value = number; ws.Cells["I33"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; ws.Cells["I33"].Style.Numberformat.Format = "0.00"; //becomes 20,00 

结果: 结果

这里是一个小例子:

 string decimalStr1 = "123,34"; string decimalStr2 = "123.34"; decimal number1, number2 = 0m; decimal.TryParse(decimalStr1.Replace(",", "."), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out number1); decimal.TryParse(decimalStr2.Replace(",", "."), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out number2); // number1 = number2 = 123.34 

重要的是使用'。' 作为分隔符和CultureInfo.InvariantCulture 。 Ant然后parsing(你确定这个值是正确的),你可以改变分隔符回到',':

 ws.Cells["I33"].Value = number1.ToString().Replace('.', ',');