简体   繁体   English

C#,微软互操作,Excel数字格式问题

[英]C#, Microsoft interop, Excel numberformat problem

I am using C# to try and format a range in Excel as numbers.我正在使用 C# 尝试将 Excel 中的范围格式化为数字。 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?如何将范围转换为数字,以便 excel 满意?

If your cells are already formatted as numbers, using the PasteSpecial function might work:如果您的单元格已经格式化为数字,使用PasteSpecial function 可能会起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM