Worksheet.Cells [x,y] .Value = NUL ... [英] Worksheet.Cells[x,y].Value=NUL...
问题描述
Code Project社区,
我在使用office.interop.excel读取xls数据时遇到麻烦.
我的大问题是,我在xls中读取了一个单元格,其中内容明确.当您直接使用excel打开此xls时,您会看到单元格的值为"101".但是当我尝试用
阅读它时
Hi community of Code Project,
im having a seroius trouble with reading data of an xls with the office.interop.excel.
My big problem is, that i read a cell in an xls, where content is defentily. When u open this xls with excel directly u can see that the value of the cell is "101". But when i try to read it with
string value = worksheet.Cells[1,1].Value as string;
我得到空返回.内容为"101"的单元格旁边的单元格的内容为"102",而其内容为"103、104、105".我可以全部阅读.只有101个单元格返回NULL.
我完全怪异. SR家伙,但我无法上传此xls,不适用于公众.
因此,我必须问是否有人对这个电池有什么了解??
tia Synergi
i get null returned. The cell beside the one with "101" as content has as content "102" and on "103, 104, 105". I can read all of them. Just the 101 cell is returning NULL.
And im totally weird. SR guys but i cant upload this xls, its not for the public available.
So i have to ask if anyone has any idea what can be with this cell???
tia Synergi
推荐答案
您应使用
as string
.
要从单元格中的任何类型的值中获取字符串,可以使用ToString()方法.
对于Excel单元格,您可能具有.Text属性或类似属性.
Pascal
only if you are sure of the type of Value.
To get a string from any kind of value in the cell, you can use the ToString() method.
For an Excel Cell, you may have a .Text property or something similar.
Pascal
我设法下载了电子表格文件(不知道昨天发生了什么),它在单元格[1、5],[1]中包含序列101、102,... ,7]等.我可以使用以下简短代码序列成功访问每个值:
I have managed to download your spreadsheet file (no idea what happened yesterday), and it contains the sequence 101, 102, ... in cells [1, 5], [1, 7] etc. I am able to access each of these values successfully with the following short code sequence:
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
for (int i = 5; i < 20; i += 2)
{
string cellValue = xlWorksheet.Cells[1, i].Value.ToString();
Console.WriteLine("Cell[1, {0}]: {1}", i, foo);
}
结果如下:
which gives these results:
Cell[1, 5]: 101
Cell[1, 7]: 102
Cell[1, 9]: 103
Cell[1, 11]: 104
Cell[1, 13]: 105
Cell[1, 15]: 106
Cell[1, 17]: 107
Cell[1, 19]: 108
我注意到的是cell [1,5]包含值101 ,而其余的单元格包含字符串.因此,您无法获取第一个单元格as string
,而需要使用ToString()
方法对其进行转换.
What I did notice is that cell[1, 5] contains the value 101, whereas the remaining cells contain strings. Thus you cannot get the first cell as string
, but need to use the ToString()
method to convert it.
这篇关于Worksheet.Cells [x,y] .Value = NUL ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!