【问题标题】:Bind a class list to Excel sheet using VSTO in c#在 C# 中使用 VSTO 将类列表绑定到 Excel 工作表
【发布时间】:2021-08-05 10:06:57
【问题描述】:

我正在使用包含一些数据的类列表,我需要使用 VSTO 绑定到 c# 中的 excel 工作表。我在VS2019中添加了VSTO包。

【问题讨论】:

    标签: c# excel vsto


    【解决方案1】:

    您可以使用Worksheet.Range 属性返回一个Range 对象,该对象表示一个单元格或一系列单元格。 range 对象表示一个单元格、一行、一列、包含一个或多个连续单元格块的单元格选择或 3-D 范围。

    以下代码示例演示了使用 Range 属性访问单个或多个单元格的不同方法:

    private void CompareRangeUsage()
    {                      
        Worksheet vstoWorksheet = Globals.Factory.GetVstoObject(
            this.Application.ActiveWorkbook.Worksheets[1]);
        // The following line of code specifies a single cell.
        vstoWorksheet.Range["A1"].Value2 = "Range 1";
    
        // The following line of code specifies multiple cells.
        vstoWorksheet.Range["A3", "B4"].Value2 = "Range 2";
    
        // The following line of code uses an Excel.Range for 
        // the second parameter of the Range property.
        Excel.Range range1 = vstoWorksheet.Range["C8"];
        vstoWorksheet.Range["A6", range1].Value2 = "Range 3";
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-28
      • 2015-08-09
      • 1970-01-01
      • 2011-08-22
      • 2018-05-06
      • 2016-03-14
      • 1970-01-01
      • 2017-08-18
      • 2014-10-28
      相关资源
      最近更新 更多