How to set Excel cell value by name instead of using coordinates with EPPlus?
I can set cell values ββusing EPPlus:
var template = new FileInfo(Server.MapPath("~/App_Data/my_template.xlsx"));
var pck = new ExcelPackage(template);
var ws = pck.Workbook.Worksheets.First();
ws.Cells[15, 4].Value = 66;
ws.Cells["B1"].Value = 55;
Instead of referring to the target cell by its coordinates, I would like to use the named cell / variable "profit".
ws.Range("profits").Value = 66;
However EPPlus does not support ws.Range (...).
=> Can this be done? How do I write an extension method that provides the required functionality?
Related articles / questions:
a) Dock for EPPlus:
b) How to use named cells / variables in Excel:
https://www.computerhope.com/issues/ch000704.htm
What is the correct way to reference named cells in Excel 2013 VBA? (I know I messed it up)
c) Libraries for creating Excel files from C #
+3
source to share
1 answer
var profits = pck.Workbook.Names["profits"];
profits.Value = 66;
from
Is there a way to get cells with names using EPPlus?
You can also set values ββfor a named range:
var ws = pck.Workbook.Worksheets.First();
using (var namedRange = pck.Workbook.Names["MyNamedRange"])
{
for (int rowIndex = namedRange.Start.Row; rowIndex <= namedRange.End.Row; rowIndex++)
{
for (int columnIndex = namedRange.Start.Column; columnIndex <= namedRange.End.Column; columnIndex++)
{
ws.Cells[rowIndex, columnIndex].Value = 66;
}
}
}
from
+2
source to share