C#,Microsoft interop,Excel数字格式问题 [英] C#, Microsoft interop, Excel numberformat problem

查看:252
本文介绍了C#,Microsoft interop,Excel数字格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#在Excel中尝试格式化一个范围作为数字。
当这样做时,我会得到角落中的绿色错误箭头,问我是否要将列格式化为一个数字。

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";

如何将范围转换为数字,以使excel很开心?

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

推荐答案

如果您的单元格已经格式化为数字,请使用 PasteSpecial 功能可能正常工作:

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);

这篇关于C#,Microsoft interop,Excel数字格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆