@manhnguyenv

Welcome to my blog!

EPPlus

September 13, 2017 21:26

Reading from an excel cell

var str = sheet.Cells[1, 1].Value;

Decimal.Parse(str, NumberStyles.Float)

Get a cell value from excel using EPPlus and Linq

var sheet = excelPackage.Workbook.Worksheets[sheetname_orSheetIndex];
var objs = from cell in sheet.Cells["a:a"]        // a:a is the column a, Userid
           where cell.Value.ToString().Equals(x)  // x is the input userid
           select sheet.Cells[cell.Start.Row, 2]; // 2 is column b, Email Address

Get all cell value

var cells = worksheet.Cells;
var dictionary = cells.GroupBy(c => new {c.Start.Row, c.Start.Column}).ToDictionary(
                rcg => new KeyValuePair<int, int>(rcg.Key.Row, rcg.Key.Column),
                rcg => cells[rcg.Key.Row, rcg.Key.Column].Value);

foreach (var kvp in dictionary)
    Console.WriteLine("{{ Row: {0}, Column: {1}, Value: \"{2}\" }}", kvp.Key.Key, kvp.Key.Value, kvp.Value);

Finding a value with Epplus

var query = 
    from cell in sheet.Cells["d:d"]
    where cell.Value?.ToString() == ""
    select cell;

Categories

Recent posts