---
title: "Writing an Excel table to Excel using Interop"  
description: "Writing an Excel table to Excel using Interop"  
author: "Royce Roy"  
published: 2014-01-30  
updated: 2014-01-30  
canonical: https://www.mindstick.com/forum/1923/writing-an-excel-table-to-excel-using-interop  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Writing an Excel table to Excel using Interop

I am using [Excel](https://www.mindstick.com/articles/12937/how-to-import-excel-data-in-sql-server-2014) [Interop](https://www.mindstick.com/forum/159638/getting-error-microsoft-office-interop-outlook-doesn-t-work) to generate Excel Table into an xlsx file. I have a very [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) table with 3 columns and no [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags), no totals but has 2 rows. Now when I generate the Excel file, I use the following code

Range rng = worksheet.Range["$A$1:$C$2"];

ListObject lo = worksheet.ListObjects.Add(xlSrcRange, rng, Type.Missing, XlYesNoGuess.xlNo);

lo.ShowHeaders = false;

With the above code it generates the table with cell range A2:C3 instead of A1:C2. But any [values](https://www.mindstick.com/forum/327/sum-textbox-values) I set in the A row are set but outside of the table. If I set the ShowHeaders to true in the 3rd line of code above, then Excel is converting the top row as the header line and still moves the [table cell](https://www.mindstick.com/forum/33993/how-to-wrap-long-text-in-a-table-cell-without-custom-cell) range to A2:C3

Am I doing [something wrong](https://www.mindstick.com/forum/12790/something-wrong-with-gridview)? I appreciate any and all help and [guidance](https://answers.mindstick.com/qa/94097/which-missile-was-developed-under-a-p-j-abdul-kalam-s-guidance) to [fix this issue](https://answers.mindstick.com/qa/94675/google-assistant-saying-something-went-wrong-how-to-fix-this-issue).

Thanks

## Replies

### Reply by Pravesh Singh

Hi Royce,\

Try this

Range rng = worksheet.Range["$A$1:$C$2"];

ListObject lo = worksheet.ListObjects.Add(xlSrcRange, rng, Type.Missing, XlYesNoGuess.xlNo);

lo.ShowHeaders = false;

Excel.Range rngRowOne = worksheet.get_Range("A1", "A1");

rngRowOne.EntireRow.Delete(Excel.XlDirection.xlUp);


---

Original Source: https://www.mindstick.com/forum/1923/writing-an-excel-table-to-excel-using-interop

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
