c# - EPPlus - Named Range is there but not working -


similar epplus - named range not populated
in case, ranges @ workbook level looking @ worksheet level. ep code shows count of 0 ranges @ workbook level , 15 @ sheet level, should be. opening worksheet.names shows 15, proper names.

retrieve range, , formula correct with
"offset(sheet1!$a$33, 0, sheet1!_currentmonth, 1, 55 -sheet1!_currentmonth)", else returns exception on evaluation.
reports 1 column, incorrect.
, 'fulladdress' looks correct "'sheet1'!_fund1projected", 'fulladdressabsolute' gives "$#ref!$-1"

lastly, i'm using template, xltm, create spreadsheet, xlsm.

        public static void createchart()     {         var excelfullpath = "c:\\users\\username\\documents\\excel\\templates\\";         var excelfilename = "lowcashbalancechart.xlsm";         fileinfo newfile = new fileinfo(excelfullpath + excelfilename);         if (newfile.exists)            newfile.delete();         fileinfo template = new fileinfo(excelfullpath + "sample chart.xltm");         using (excelpackage xlpackage = new excelpackage(newfile, template))         {             excelworksheet worksheet = xlpackage.workbook.worksheets["sheet1"]; //xlpackage.workbook.worksheets.firstordefault();              excelnamedrange namedrange;             namedrange = xlpackage.workbook.names["_fund1projected"]; // fails, no ranges @ wb level             namedrange = worksheet.names["_fund1projected"]; // 1 works                            (int rowindex = namedrange.start.row; rowindex <= namedrange.end.row; rowindex++)  // exception on range.start             // 'namedrange.start' threw exception of type 'system.argumentoutofrangeexception'             {                 (int columnindex = namedrange.start.column; columnindex <= namedrange.end.column; columnindex++)                 {                     worksheet.cells[rowindex, columnindex].value = (rowindex * 100 + columnindex).tostring();                  }             }              xlpackage.save();         }     } 

i looked @ code on github, nothing stands out.
tried ranges @ workbook level same results.

i solved problem, i'll put answer here may need in future.

i created range 3x3 square. range1 = =sheet1!$a$24:$c$26

i can write fine. no exceptions.

but when have ranges have endpoints determined values of other cells, fails.

=offset(sheet1!$a$32, 0, sheet1!_currentmonth, 1, 55 -sheet1!_currentmonth)

the problem our named ranges dynamic. that’s why getting exception.

the work-around not use dynamic ranges epplus. little more c# code handle dynamic part instead of excel handling you.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo