I'm using Excel.Interop
我用Excel.Interop
This is the code for traversing through the excel cells :
这是遍历excel单元格的代码:
for(i=1 ; i< 10; i++)
{
for (int j = 1; j < 10; j++) // 10 is no of columns(static)
{
oRng = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[i + 1, j+1]; // getting value here(its "")
string strValue = oRng.Text.ToString();
dr[j - 1] = strValue;
}}
I have a column hidden in the excel sheet, n when i iterate over that cell, i'm getting ""
. I dont know as to what should be done in order to get that cell's value.
我在excel表格中有一个列,当我遍历那个单元格时,我得到""我不知道为了得到这个单元格的值该做些什么。
thanks
谢谢
PS: the dr
used here is a DataRow
which i'm further storing it in DataSet
这里使用的dr是DataRow,我将它存储在数据集中。
3 个解决方案
#1
2
Here. Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
在这里。微软目前不建议也不支持Microsoft Office应用程序从任何无人参与的、非交互式客户端应用程序或组件(包括ASP、ASP)实现自动化。NET、DCOM和NT服务),因为在此环境中运行Office时,Office可能会显示不稳定的行为和/或死锁。
I recommend you to look for a free library like Open Office XML or a not free library like Aspose.
我建议您寻找一个免费的库,如Open Office XML或一个不免费的库,如Aspose。
#2
1
try this
试试这个
Public string gethiddenexcellcolumns()
{
Excel.Application excel = New Excel.Application();
excel.Visible = True;
excel.Workbooks.Add();
excel.Columns("C:C").Select();
excel.Selection.EntireColumn.Hidden = True;
var columns = excel.Columns;
bool hasHiddenColumns = false;
foreach(column in columns)
{
If(column.Hidden==true)
{
hasHiddenColumns = true
}
}
return "excel.Columns.Hidden = " + hasHiddenColumns.ToString();
}
#3
0
Even i tried doing this in my solution, but, I think the hidden files cant be read when hidden. but one work around( not recommended) is u could just make the hidden cells/columns hidden to false right before u are reading values from the excel sheet. Like Worksheetobject.Cells[row,colum].Hidden = false
. This is not recommended, but works if u want to make it hidden and access.
甚至我在我的解决方案中也尝试过这样做,但是,我认为隐藏的文件在隐藏时是无法读取的。但有一种方法(不推荐)是,在u从excel表中读取值之前,您可以将隐藏的单元格/列隐藏为false。像Worksheetobject.Cells(行,科勒姆)。隐藏的= false。这是不推荐的,但是如果你想让它隐藏和访问的话,这是可行的。
#1
2
Here. Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
在这里。微软目前不建议也不支持Microsoft Office应用程序从任何无人参与的、非交互式客户端应用程序或组件(包括ASP、ASP)实现自动化。NET、DCOM和NT服务),因为在此环境中运行Office时,Office可能会显示不稳定的行为和/或死锁。
I recommend you to look for a free library like Open Office XML or a not free library like Aspose.
我建议您寻找一个免费的库,如Open Office XML或一个不免费的库,如Aspose。
#2
1
try this
试试这个
Public string gethiddenexcellcolumns()
{
Excel.Application excel = New Excel.Application();
excel.Visible = True;
excel.Workbooks.Add();
excel.Columns("C:C").Select();
excel.Selection.EntireColumn.Hidden = True;
var columns = excel.Columns;
bool hasHiddenColumns = false;
foreach(column in columns)
{
If(column.Hidden==true)
{
hasHiddenColumns = true
}
}
return "excel.Columns.Hidden = " + hasHiddenColumns.ToString();
}
#3
0
Even i tried doing this in my solution, but, I think the hidden files cant be read when hidden. but one work around( not recommended) is u could just make the hidden cells/columns hidden to false right before u are reading values from the excel sheet. Like Worksheetobject.Cells[row,colum].Hidden = false
. This is not recommended, but works if u want to make it hidden and access.
甚至我在我的解决方案中也尝试过这样做,但是,我认为隐藏的文件在隐藏时是无法读取的。但有一种方法(不推荐)是,在u从excel表中读取值之前,您可以将隐藏的单元格/列隐藏为false。像Worksheetobject.Cells(行,科勒姆)。隐藏的= false。这是不推荐的,但是如果你想让它隐藏和访问的话,这是可行的。