Users Pricing

forum

Home Forums Writing an Excel table to Excel using Interop – MindStick

Writing an Excel table to Excel using Interop

Royce Roy 2343 30 Jan 2014

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


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md