locked
EPPlus, .NET Core3 and setting value of Excel cell RRS feed

  • Question

  • User1993186009 posted

    Hi,

    Trying to get & update an existing cell's value:

    var q1 = worksheet.Cells["A11"].Value; // here I get a non-empty string
    worksheet.Cells["A11"].Value = "new string";
    var q2 = worksheet.Cells["A11"].Value; // returns EMPTY. WHY?????

    I don't understand why my last string returns an empty value. How am I supposed to set cell's value in a correct way?

    Friday, April 30, 2021 4:31 PM

All replies

  • User475983607 posted

    Hi,

    Trying to get & update an existing cell's value:

    var q1 = worksheet.Cells["A11"].Value; // here I get a non-empty string
    worksheet.Cells["A11"].Value = "new string";
    var q2 = worksheet.Cells["A11"].Value; // returns EMPTY. WHY?????

    I don't understand why my last string returns an empty value. How am I supposed to set cell's value in a correct way?

    You did not share enough code to reproduce the issue.  I created the follow sample from the EPPlus docs and it just works.

    https://www.epplussoftware.com/en/Developers/

    static void Main(string[] args)
    {
        var file = new FileInfo(@"c:\temp\myWorkbook.xlsx");
        using (var package = new ExcelPackage(file))
        {
            var sheet = package.Workbook.Worksheets.Add("My Sheet");
            sheet.Cells["A1"].Value = "Hello World!";
    
            Console.WriteLine(sheet.Cells["A1"].Value);
    
            // Save to file
            package.Save();
        }
    }

    Friday, April 30, 2021 6:31 PM
  • User1993186009 posted

    Ok, what if you try to merge cells say from A1 to A6, set in the underlying Excel a text value for this merged cell and then try to read & update & read again? In my case I get an empty string instead of the recently set value in the merged cells.

    Friday, April 30, 2021 6:52 PM
  • User475983607 posted

    Ok, what if you try to merge cells say from A1 to A6, set in the underlying Excel a text value for this merged cell and then try to read & update & read again? In my case I get an empty string instead of the recently set value in the merged cells.

    Ok, what if you read the EPPlus support documentation?  Or share the actual code you are having trouble with rather than making the community guess. 

    Friday, April 30, 2021 6:56 PM