Resize an Excel Table from C# Using Interop
Question details
Resize an Excel table from a C# application as the amount of generated data changes.

- 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.
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.
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.
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.
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"].
Call the ListObject method with the target range: table.Resize(worksheet.Range["A1:B10"]); Replace B10 with the calculated last cell for your data.
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.

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.

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.




