Search code examples
gembox-spreadsheet

LineBreak within an excel cell using GemBox Spreadsheet


Is it possible to add a line break within an excel cell using the GemBox Spreadsheet API? For example if you're in Excel you can press Alt+Enter and go to a new line in a cell. I'm having trouble finding a property on the CellStyle class in GemBox that allows this. Is it possible?

Thanks


Solution

  • Yes, it is possible, for example try the following:

    var ef = new ExcelFile();
    var ws = ef.Worksheets.Add("Sheet1");
    
    ws.Cells["A1"].Value = "Sample";
    ws.Cells["A1"].Value += "\n" + "Sample";
    
    ef.Save("Sample.xlsx");
    

    In short, just use the new line character in ExcelCell.Value.
    Note that when you're assigning such a value, GemBox.Spreadsheet will automatically set ExcelCell.Style.WrapText property to true.