c# - 在 C# 中使用 VSTO 将类列表绑定到 Excel 工作表
问题描述
我正在使用包含一些数据的类列表,我需要使用 VSTO 绑定到 c# 中的 excel 表。我在 VS2019 中添加了 VSTO 包。
解决方案
您可以使用Worksheet.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";
}
推荐阅读
- jsf - 如何获取知道其 id 的 jsf 组件父级的 id?
- javascript - 在 JS 中具有许多数据点的绘图
- c - long int、long long int 和 int 的范围
- symfony - Symfony elasticsearch 2个词查询没有结果
- algorithm - 如何定义哪些对角线属于凹多边形
- java - 如何使用 Inno Setup 在安装过程中下载 JRE
- pyqt5 - 从源安装 PyQt5:无法导入 PyQt5.sip
- ruby - 捆绑包找不到已安装的 gem
- vba - 使用 VBA 从 Visio Shapes 导出数据
- clojure - 尝试调用未绑定的 fn:#'datoteka.core/to-file