【问题标题】:Printing and using Var within a ListObject forloop在 ListObject forloop 中打印和使用 Var
【发布时间】:2017-03-11 08:25:54
【问题描述】:

我目前拥有可以访问 table1 的 C# 代码。但是,我遇到了 Var listRowsValue 和 var lr 的问题。如何打印这些并从 ListRowsValue 中减去 1,而不是将“System._ComObject”视为输出?如何调整 ListObject 的大小以不在计数结束时检查另一行?

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

【问题讨论】:

    标签: c# vsto excel-interop listobject


    【解决方案1】:

    VSTO 的使用与常规 C# 库完全不同,因为它高度依赖于 COM。

    lr 是一个ListRow 对象。

    使用lr.Range.Text 获取其中的文本。

    Console.WriteLine("CURRENT ROW: " + lr.Range.Text);
    

    见Range.Text。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多