You seem to be confusing the ExcelPackage
project and the EPPlus
project. I can see how as they share namespaces and class names (I don’t know the history of either to know if they’re related or not).
You have a reference to the ExcelPackage
dll in your example. The ExcelWorksheet
class there doesn’t have a Cells
property; instead it has a Cell
method.
The ExcelWorksheet
class in EPPlus
does have a Cells
property that returns an ExcelRange
. The ExcelRange
in turn has an indexer that looks like this which would allow the code you have to work:
public ExcelRange this[int Row, int Col]
To get your code to work using ExcelPackage
you will need to change to using the method:
worksheet.Cell(row, col).Value = (row * col).ToString();
Note that the Value
property is a string
so I’m calling ToString()
If you would prefer to keep your code as is you could remove the reference to ExcelPackage
and add a reference to EPPlus
instead (which is available on Nuget). I have no idea which is better but running your code against both (with the above fix for the ExcelPackage
version) gives me a warning when loading the file created by ExcelPackage
in Excel but it doesn’t for the one created via EPPlus
.
solved Which references am I missing?