I'm using EPPLus to open Excel Spreadsheets and trying to read from a named range. The Named Range is Empty.
Am I using this wrong, or is it a problem with EPPlus
Code
var package = new ExcelPackage();
using (var stream = File.OpenRead(tmpExcel))
{
package.Load(stream);
}
var worksheet = package.Workbook.Worksheets["Common-Lookup"];
using (ExcelNamedRange namedRange = worksheet.Names["LupVerticalSettings"])
{
for (var row = namedRange.Start.Row; row <= namedRange.End.Row; row++)
{
for (var col = namedRange.Start.Column; col <= namedRange.End.Column; col++)
{
_.Nv(worksheet.Cells[row, col].Address, worksheet.Cells[row, col].Text);
//worksheet.Cells[rowIndex, columnIndex].Value = "no more hair pulling";
}
}
}
The Excel looks like this
Empty Named Range
I solved my problem, I'll put answer here for anyone that may need it in the future
var package = new ExcelPackage();
using (var stream = File.OpenRead(tmpExcel))
{
package.Load(stream);
}
var worksheet = package.Workbook.Worksheets["Common-Lookup"];
// Access Named Ranges from the ExcelWorkbook instead of ExcelWorksheet
//using (ExcelNamedRange namedRange = worksheet.Names["LupVerticalSettings"])
// use package.Workbook.Names instead of worksheet.Names
using (ExcelNamedRange namedRange = package.Workbook.Names["LupVerticalSettings"])
{
for (var row = namedRange.Start.Row; row <= namedRange.End.Row; row++)
{
for (var col = namedRange.Start.Column; col <= namedRange.End.Column; col++)
{
_.Nv(worksheet.Cells[row, col].Address, worksheet.Cells[row, col].Text);
//worksheet.Cells[rowIndex, columnIndex].Value = "no more hair pulling";
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With