C#, Microsoft interop, Excel numberformat problem

◇◆丶佛笑我妖孽 提交于 2020-01-04 06:18:24

问题


I am using C# to try and format a range in Excel as numbers. When doing this, I get the green error arrow in the corner to ask me if I want to format the column as a number.

I used the code below to format the data:

Excel.Range Data = currentSheet.get_Range("K2:K10", Type.Missing);
Data.NumberFormat = "0.00";

How do I convert the range to numbers so that excel is happy?


回答1:


If your cells are already formatted as numbers, using the PasteSpecial function might work:

Excel.Range Data = currentSheet.get_Range("K2:K10", Type.Missing);
Data.Copy(System.Type.Missing);
Data.PasteSpecial(XlPasteType.xlPasteAll, XlPasteSpecialOperation.xlPasteSpecialOperationAdd,
        false, false);


来源:https://stackoverflow.com/questions/6661208/c-microsoft-interop-excel-numberformat-problem

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