Search code examples
c#excelepplus

EPPLUS insert more than 1000 characters in cell value


Is there a way to insert more than 1000 chars in cell value? Now it gets cut off. Maybe is there a way to append values?

I couldn't find anything regarding this topic. I went trough all the options after OfficeOpenXml.ExcelWorksheet.Cell and did not find anything. Right now I set the cell value like this: OfficeOpenXml.ExcelWorksheet.Cell[A1].Value = 'something' and something this 'something' exceed 1000 chars.


Solution

  • I can't reproduce any problem. The following code using EPPlus 6.2 creates an Excel sheet with 4001 characters in C2, ending in z:

    using OfficeOpenXml;
    
    ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
    
    var file = new FileInfo("MyWorkbook.xlsx");
    file.Delete();
    using var package = new ExcelPackage(file);
    
    var worksheet = package.Workbook.Worksheets.Add("Inventory");
    //Add the headers
    worksheet.Cells[1, 1].Value = "ID";
    worksheet.Cells[1, 2].Value = "Product";
    worksheet.Cells[1, 3].Value = "Notes";
    
    //Add some items...
    worksheet.Cells["A2"].Value = 12001;
    worksheet.Cells["B2"].Value = "Nails";
    worksheet.Cells["C2"].Value = new String('a',4000) + "z";
    
    worksheet.Cells["C3"].Formula = "LEN(C2)";
    package.Save();
    

    Screenshot of very long Excel cell shows the text overflowing to the right

    Trying to edit in-place shows all the characters, including the final z :

    In-place editing of very long cell shows all the characters in a very tall box

    Using the edit box may give the impression there aren't enough characters because the text is wrapped and End goes to the end of the line, not the end of the cell.

    Edit box after hitting End shows only the end of the first visible line

    Ctrl+End will go to the end of the cell though

    Edit box after hitting Ctrl+End shows the z character