Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Named range EPPlus

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();
like image 794
Carlos Siestrup Avatar asked Dec 06 '25 18:12

Carlos Siestrup


2 Answers

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);
like image 172
Lyco Avatar answered Dec 08 '25 09:12

Lyco


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);
like image 24
Gilles Boisson Avatar answered Dec 08 '25 08:12

Gilles Boisson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!