Excel Range Format: Number is automatically formatted when Range::Value2 is set

自闭症网瘾萝莉.ら 提交于 2019-12-25 03:38:44

问题


I have an Excel addin written in C# that imports a text file into Excel worksheet. Some of the fields in the file are text and some oare numbers.

Problem Steps:

  1. Change the System's Regional Settings to Dutch (Belgium)
  2. Open Excel and import the file into Excel. Records contain values such as 78,1118 which gets converted to 781.118. Note that in Dutch(Belgium), COMMA is the decimal character and DOT is the thousand character.

I do not require the number to be formatted automatically but just want to display whatver I get from the file (78,1118). If I set the cell's NumberFormat to "@" i.e. Text, then it displays an error (SmartTag) saying "Number stored as Text". I know I can change the settings by going to the "Options" box but I dont want to change any user options in Excel for this. I have tried setting the cell's Value2 with an "'" (apostrophe) but the same error is displayed. If I set the cell's format to something else after the value is set then the actual value changes and I loose the decimal.

Is there a way in Excel to just display the value and NOT display the "Number Stored as Text" error in cell?


回答1:


in c#

ExcelApplication.ErrorCheckingOptions.NumberAsText=false


来源:https://stackoverflow.com/questions/1410422/excel-range-format-number-is-automatically-formatted-when-rangevalue2-is-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!