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
30-Jan-2014Try 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);