0
我目前擁有訪問table1的C#代碼。然而,我有一個問題與Var listRowsValue和var lr。我怎樣才能打印這些並從ListRowsValue中減去1而不是查看「System._ComObject」作爲輸出?如何調整ListObject的大小以便在計數結束時不檢查另一行?在ListObject forloop中打印和使用Var內的變量
var listRowsValue = xlWorkBook.Worksheets["Sheet1"].ListObjects["table1"].ListRows;
for (int CurrentRow = 0; CurrentRow < listRowsValue.Count; CurrentRow++)
{
if (xlWorkBook.Worksheets["Sheet1"].ListObjects["table1"].Range[CurrentRow, 2].value == -1)
{
xlSheet.Cells[5, 5] = "YES!";
//lr.Range.Clear();
var lr = listRowsValue[CurrentRow];
Console.WriteLine("CURRENT ROW: " + lr);//Why does this not work?
//MoveEmUpOne();
//How do I resize the total listRowsValue count here so it doesn't check another row at the end?
//EXAMPLE: ListRowsValue = ListRowsValue - 1;
//CurrentRow = CurrentRow - 1;
}
else
{
xlSheet.Cells[5, 5] = "NO!";
}
}
舊VBA代碼我從轉換:
For CurrentRow = 1 To Tablesize
If Lo.ListColumns("Column2").DataBodyRange(CurrentRow) = -1 Then
Ros(CurrentRow).Range.Clear
MoveEmUpOne Lo, CurrentRow, Tablesize
Tablesize = Tablesize - 1 'table didn't really get smaller, but number of "real"rows decreased by 1
CurrentRow = CurrentRow - 1 ' check this row again -- stuff from below might need cleard
End If