I have a template excel file that I populate with data using the SQL Server OLEDB connector. The file contains some pivot tables that reference the dataset populated by the database.
I am currently doing that I select all rows in a sheet using the range "Data! $ A: $ K". This causes a problem with the null values displayed in the pivot table.
What I wanted to do was create a named dataset table and assign pivot tables to it (plus I get some other benefits that the name tables bring).
The number of rows is naturally not set, so I wanted to find a way to set the scope with the named range to only valid values.
I am using Excel Interop and C # for this, and I cannot find a way to change the range. I just got to:
oRng = oSheet.get_Range("Transactions");
Which chooses a named range. But how do I change which cells belong to him?
Or maybe the best solution I should pursue?
EDIT
Dynamic ranges are the answer!
I solved this thanks to @TimWilliams answer:
"Use dynamic range in your template: http://ozgrid.com/Excel/DynamicRanges.htm "
I feel that dynamic ranges are being described here: http://www.contextures.com/xlpivot01.html
I had a small problem, because of which I could not use the range in the pivot table, because I required it to have at least 2 rows to work - the template file has only column headers. I added a random row to the 1st cell of the 2nd row and the pivot table adopted for this.
Subsequently, I had to delete this line using C # code.
Thanks guys for the help.