简体   繁体   English

将行添加到Excel表

[英]Adding a Row to an Excel Table

I am working on an Excel 2013/2015 VSTO workbook application. 我正在使用Excel 2013/2015 VSTO工作簿应用程序。 From data entered in a Windows form I'd like to create a new record in an existing Table on one of my worksheets. 从Windows窗体中输入的数据中,我想在一个工作表的现有表中创建一个新记录。

How do I insert a new Table row into an Excel Table (not a simple worksheet array) using C# and VSTO? 如何使用C#和VSTO将新的表格行插入Excel表格(不是简单的工作表数组)?

The Microsoft.Office.Tools.Excel.ListObject provides the needed functionality. Microsoft.Office.Tools.Excel.ListObject提供了所需的功能。 The table can be referenced and rows added as follows: 可以引用该表并添加行,如下所示:

Microsoft.Office.Tools.Excel.ListObject lo = Globals.Sheet1.MyTable;
lo.ListRows.Add();

Optionally, the position of the new row can be specified ( https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.listrows.add.aspx ). (可选)可以指定新行的位置( https://msdn.microsoft.com/zh-cn/library/microsoft.office.interop.excel.listrows.add.aspx )。 Default is at the end of the table. 默认值在表格末尾。

IntelliSense did not show the Add() function in my case, which caused the confusion. 在我的案例中,IntelliSense没有显示Add()函数,这引起了混乱。 Just type it in. 只需输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM