C# - Excel Number Formatting Issue with International settings

后端 未结 4 1034
说谎
说谎 2021-01-15 06:32

I am trying to write to an Excel 2003 spreadsheet using c# 3.5. However I am unable to get this to function correctly across different country settings. The country settings

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-15 07:18

    I haven't run your code, just scanned it...

    First potential Problem: You are checking UseSystemSeparators and then setting the DecimalSeparaor and ThousandsSeparator.

            if (app.UseSystemSeparators == false)
            {
                app.DecimalSeparator = ci.NumberFormat.NumberDecimalSeparator;
                app.ThousandsSeparator = ci.NumberFormat.NumberGroupSeparator;
            }
    

    Then right after, you are turning on SystemSeparators, so the code above is not doing anything since you are turning the system seperators on.

            app.UseSystemSeparators = true;
    

    Second potential problem/suggestion: When setting the cell value, set it as a double value instead of string, let Excel format the number for you.

提交回复
热议问题