Friday, October 25, 2013

New line break problem with EPPLUS when exporting data


Recently i have been facing an issue while exporting data  using C# and EPPLUS. I used below solution to get that done ::

Since my data is coming from stored procedure and this data is stored in a single column, i used a special character to seperate data.


so in excel this will be displayed as


if you send data from DB like for example :: ENTRY1\r\nENTRY2, it didnt work even if i convert that to a string. So, i replaced this special character in my c# code.

  int rowCnt=ws.Dimension.End.Row;
           for (int i = 1; i <= rowCnt; i++)
             using (var rngs = ws.Cells["FD"+i])
               var rt1 = rngs.RichText.Text;
               if (!string.IsNullOrEmpty(rt1))
                 rngs.Style.WrapText = true;
                 var rt2 = rng.RichText.Add(rt1.Replace("***", "\r\n"));
                 rngs.Style.WrapText = true;


Ujjwal Soni

No comments: