简体   繁体   中英

Adding a Row to an Excel Table

I am working on an Excel 2013/2015 VSTO workbook application. From data entered in a Windows form I'd like to create a new record in an existing Table on one of my worksheets.

How do I insert a new Table row into an Excel Table (not a simple worksheet array) using C# and VSTO?

The Microsoft.Office.Tools.Excel.ListObject provides the needed functionality. 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 ). Default is at the end of the table.

IntelliSense did not show the Add() function in my case, which caused the confusion. Just type it in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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