Others

Resize an Excel Table from C# Using Interop

Emma BrownEmma Brown Nov 13, 2026 869 views

Question details

Resize an Excel table from a C# application as the amount of generated data changes.

Resize an Excel Table from C# Using Interop
Product
Microsoft Excel and Microsoft.Office.Interop.Excel
Device & OS
not provided
Scenario
A C# application generates bowling league statistics in an XLSX workbook that is distributed through OneDrive and viewed in Excel mobile apps.
Observed behavior
The table needs to cover a variable number of statistics rows without relying on VBA or an XLSM file.
Before you start

Add a reference to Microsoft.Office.Interop.Excel and obtain a worksheet from an open workbook in your C# application. Identify the table and calculate the target range, including its header row and all intended columns.

Solution 1Recommended

Resize the Excel ListObject with C# Interop

Use the Excel object model to change the table range without Microsoft.Office.Tools.Excel or VBA.

An Excel table is represented by a ListObject. Its Resize method changes the range assigned to the table; it does not populate the cells with data.

Interop automates the Excel application, so Excel must be available in the environment where the code runs.

1
Get the table

From the worksheet containing the table, access its ListObjects collection. For example: Excel.ListObject table = worksheet.ListObjects[1]; where Excel is an alias for Microsoft.Office.Interop.Excel.

2
Set the target range

Calculate the range from the table's existing header position and the size of the generated data. For a table starting at A1 with two columns and nine data rows, use worksheet.Range["A1:B10"].

3
Resize the table

Call the ListObject method with the target range: table.Resize(worksheet.Range["A1:B10"]); Replace B10 with the calculated last cell for your data.

4
Save the workbook

Write the generated values to the worksheet and call workbook.Save() for an existing XLSX file. Save the file to the OneDrive location used for distribution.

Resize the Excel ListObject with C# Interop
Keep the table header: The target range must include the existing table header row. Check that the range covers the intended data and does not overlap another table.
Free Microsoft Office alternative

View and edit Excel workbooks with WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Excel formats, making it easy to move existing workbooks into WPS. It does not replace Microsoft Excel for the C# Interop automation described above.

Open and edit spreadsheet data in a familiar interfaceWork with Microsoft Excel XLSX and XLS filesReview league statistics in a lightweight office suiteMove existing compatible workbooks into WPS Office
microsoft office alternative - wps office

Frequently Asked Questions

Do I need Microsoft.Office.Tools.Excel to resize the table?

No. With Microsoft.Office.Interop.Excel, access the worksheet's ListObjects collection and call Resize on the desired ListObject.

Does resizing the table add my generated statistics?

No. Resize changes the table's range. Write the statistics into the worksheet cells separately, then save the workbook.

Can I keep the workbook in XLSX format?

Yes. The resize is performed by the C# application rather than a VBA macro, so the workbook does not need to be saved as XLSM. Call workbook.Save() if it is already an XLSX file.

How do I choose the range for a variable number of rows?

Start with the table's existing header row and calculate the last row from the number of data rows. For example, A1:B10 includes a header in row 1 and nine data rows.