private void LoadExcelSheet(string path, int sheet){
_Application excel = new Excel.Application();
Workbook wb;
Worksheet ws;
string data = "";
int row = 0;
int col = 0;
wb = excel.Workbooks.Open(path);
ws = wb.Worksheets[sheet];
listBox1.Items.Clear();
for (row = 1; row < 10; row++){
data = " ";
for (col = 1; col < 3; col++) {
data += ws.Cells[row, col].Value2 + " ";
}
//wanted to filter out empty cells/data and at the same time count
//number of items in the list... row should stop.. I think!
if(data == null){
break;
}
listBox1.Items.Add(data);
}
无论我做什么,if
声明似乎都不起作用。如果有人能指出我正确的方向,我将非常感激。
答案 0 :(得分:1)
像这样使用它:
if (data.Trim().Length < 1)
{
return;
}
使用return
而不是break
答案 1 :(得分:0)
添加这样的条件
Person