3

I'm using EPPlus to populate an excel file, I have many pivot tables that refresh when the file is opened.

Their source is always one of the two sheets populated by my application.

The problem is that everytime I populate there is a different number of rows, I tried using a named range in their source but when I change the range of the named range with EPPlus , it doesnt work.

   epplusWs.Workbook.Names["named_range"].Address = "data_sheet!$A$1:$H$" + row.ToString();
Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
Carlos Siestrup
  • 1,031
  • 2
  • 13
  • 33

2 Answers2

1

This is a late answer but you could add a new named ranged like this:

    ExcelNamedRange NR = new ExcelNamedRange("named_range", sheet: worksheet, nameSheet: worksheet, address: <your address string here>, index: 1);
    package.Workbook.Worksheets[1].Names.Add("named_range", NR);
Lyco
  • 549
  • 3
  • 14
  • just an fyi, this solution doesn't work any more since the version 5.1.2 - this constructor scope is now set to internal in this version, it is recommended to use Gilles Boisson way instead – Kalpesh Popat May 30 '20 at 05:37
1

I find a way to edit an existing one :

var range = epplusWs.Workbook.Names[rangeName];
range.Address = "YourNewRange";
epplusWs.Workbook.Names.Remove(rangeName);
epplusWs.Workbook.Names.Add(rangeName, range);