Reputation: 46222
I have an excel file. I simply need a cell value. I am having a hard time finding documentation on this. I have done ClosedXML before where I write date to an excel file but not where I read from it.
const string fileName =
@"C:\Folder1\Form.xlsx";
// Retrieve the value in cell A1.
var workbook1 = new XLWorkbook(fileName);
var ws1 = workbook1.Worksheet(1);
Any help would be appreciated.
Upvotes: 3
Views: 5425
Reputation: 17550
There are multiple possibilities to get a cell and its value depending on the data type:
var cell = ws.Cell("A1");
var cell = ws.Cell(1, 2); // row 1, column 2
object result = cell.Value;
string result = cell.Value.ToString(); // if you want to get text
string result = cell.GetValue<string>(); // also for text
int result = cell.GetValue<int>(); // for integer numbers
And more for other datatypes.
Upvotes: 5