C#访问EXCEL,格式化小区作为一般 [英] C# Accessing EXCEL, formating cell as General

查看:123
本文介绍了C#访问EXCEL,格式化小区作为一般的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#,Visual Studio 2010中

C#, Visual studio 2010

当(通过COM对象)在C#Excel单元格操纵,我应该使用的。价值或.Value2?

When manipulating excel cells in C# (via an COM object), should I use the .Value or .Value2 ? that is

 sheet.Cells[row + n, col].Value = "Hello world"

 sheet.Cells[row + n, col].Value2 = "Hello world"

什么是它们之间的区别?

What is the difference between them to ?

另外,我怎么设置单元格格式常规?

Also, how do I set a cell format to "General" ?

sheet.Cells[row + n, col].NumberFormat = "XYZ";  // Not sure what should be here



现在,当我分配一个细胞与数字0, 34即使我做

Right now when I assign a cell with the number "0,34" and even if I do

sheet.Cells[row + n, col].NumberFormat = "@"; 



我得到了在每个单元格左上角这个小错误签署

I get this "little error" sign up in the left corner in each cell

/斯特凡

推荐答案

要回答,你应该读这篇文章的第一个问题:<一HREF =http://blogs.msdn.com/b/eric_carter/archive/2004/09/06/225989.aspx相对=nofollow> http://blogs.msdn.com/b/eric_carter/archive /2004/09/06/225989.aspx

To answer the first question you should read this article: http://blogs.msdn.com/b/eric_carter/archive/2004/09/06/225989.aspx

可选的参数部分不适用了,因为C#4.0具有可选参数。

The optional parameters part doesn't apply anymore since C# 4.0 has optional parameters.

但有区别(在文章中说明)

But there IS a difference (stated in the article)

此属性之间的唯一区别[值2]和值
属性是Value2属性不使用货币和日期
的数据类型。您可以通过使用双数据类型返回这些数据类型为
浮点数格式的值。

The only difference between this property [Value2] and the Value property is that the Value2 property doesn’t use the Currency and Date data types. You can return values formatted with these data types as floating-point numbers by using the Double data type.

有关的第二个问题,你有没有尝试过的单元格设置为常规,然后读出来的代码?

For the second question, have you tried setting a cell to 'General' and reading it out in code?

我觉得这是 sheet.Cells [行+ N,COL] .NumberFormat =常规,其中@为纯文本。

I think it's sheet.Cells[row + n, col].NumberFormat = "General", where "@" is pure text.

这篇关于C#访问EXCEL,格式化小区作为一般的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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