-1

I want to send excel data with formatting in an email body. I want to use C# as the language and will use Epplus library to read excel data. I just want to automate that code and make an application. I have knowledge of how to send an email and everything.

Note: The email should contain the formatting and styles that are done in the excel. It should work like when we copy paste some data from excel file and paste them in the email.

Just tried using regular body data in email. But formatting is missing.

Ralf
  • 16,086
  • 4
  • 44
  • 68
Sasuke Uchiha
  • 91
  • 1
  • 10
  • 1
    What have you tried so far? Could you show your attempts so far and the concrete issues you are facing? – Ralf Jun 05 '19 at 12:21

1 Answers1

0

You can easily iterate through columns and rows and generate html in any shape you want. and finally email html.

public string XlsxToHTML(byte[] xmlFile)
{
   var sb = new StringBuilder();
   var stream = new MemoryStream(xmlFile);
   sb.Append("<table>");

   using(ExcelPackage excelPackage = new ExcelPackage(stream))
   {
      ExcelWorkbook workbook = excelPackage.Workbook;
      if(workbook!=null)
      {
         ExcelWorksheet worksheet = workbook.Worksheets.FirstOrDefault();
         if(worksheet!=null)
         {
            var firstCell = worksheet.Cells[1,1].Value;
            var secondCell = worksheet.Cells[1,2].Value;

            sb.Append("<tr><td>"+firstCell+"</td></tr>");
            sb.Append("<tr><td>"+firstCell+"</td></tr>");
         }
      }
   }

   sb.Append("</table>");

   return sb.ToString();
}
  • Will this copy the data with all the formatting and styles ? I don't think it will do that. But can you please confirm it. – Sasuke Uchiha Jun 05 '19 at 07:22