Home > DeveloperSection > Forums > Writing an Excel table to Excel using Interop
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    January-30-2014 11:11 PM

 C# C# 
Ratings:


 1 Reply(s)
 811  View(s)
Rate this:

I am using Excel Interop to generate Excel Table into an xlsx file. I have a very simple table with 3 columns and no header, 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 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 range to A2:C3

Am I doing something wrong? I appreciate any and all help and guidance to fix this issue.

Thanks



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-30-2014 11:32 PM

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);


Don't want to miss updates? Please click the below button!

Follow MindStick