locked
How to export html table in sql database to excel. RRS feed

  • Question

  • User-525375510 posted
    Hi all,
    I meet 1 problem with MVC4 export using EPPlus.
    I have 1 data in database as below:

    <strong>This is demo data <br />
    <img alt="" src="/Images/images/Koala.jpg" style="height:150px; width:200px" /></strong>


    Now i want to export this data to excel include Image follow above path.
    How to export to excel include image?
    Sunday, January 11, 2015 9:15 PM

All replies

  • User-1990124160 posted

    dophuong_cs

    Hi all,
    I meet 1 problem with MVC4 export using EPPlus.
    I have 1 data in database as below:

    <strong>This is demo data <br />
    <img alt="" src="/Images/images/Koala.jpg" style="height:150px; width:200px" /></strong>


    Now i want to export this data to excel include Image follow above path.
    How to export to excel include image?

    Are you getting any error? Here are some links that show how to export images using EPPlus:

    stackoverflow.com/questions/13174380/placing-image-inside-excel-file

    stackoverflow.com/questions/11588704/adding-images-into-excel-using-epplus

    Monday, January 12, 2015 2:03 AM
  • User-525375510 posted
    Hi IbrahimIslam,
    Thank you very much for your great support.
    However, i want to se how to export data from database to excel include picture.
    My column in database contain below data:

    <strong>This is demo data <br />
    <img alt="" src="/Images/images/Koala.jpg" style="height:150px; width:200px" /></strong>

    How to export together above content to 1 row on excel sheet.
    Please support!
    Monday, January 12, 2015 2:15 AM
  • User-1990124160 posted

    <strong>This is demo data <br />
    <img alt="" src="/Images/images/Koala.jpg" style="height:150px; width:200px" /></strong>

    Do you want to export the above whole HTML as text or the image and text inside?

    Monday, January 12, 2015 4:23 AM
  • User-525375510 posted
    Hi IbrahimIslam,
    Thank you very much!
    I want to export above HTML as Text and text inside, however how to display image inside cell of excel.
    How to do it?Please support me.
    Monday, January 12, 2015 5:07 AM
  • User-1990124160 posted

    Hi IbrahimIslam,
    Thank you very much!
    I want to export above HTML as Text and text inside, however how to display image inside cell of excel.
    How to do it?Please support me.

    Paste in your existing code and you can try some tutorials as well: http://zeeshanumardotnet.blogspot.com/2011/06/creating-reports-in-excel-2007-using.html

    Monday, January 12, 2015 7:44 AM
  • User-525375510 posted

    Thank you for your support!<br>
    This forum don't have space to upload picture.<br>
    I want to show you my out put.<br>
    After that you are easy to support.

    My code to export

    public ActionResult Eri_Cover_Sheet_PE1(string Eri_No)
    {

    FileInfo templateFile = new FileInfo(this.Request.PhysicalApplicationPath + "Upload Template/ECN_Cover_Sheet_PE1.xlsx");
    Ecn_Cover_PE1s = _db.Database.SqlQuery<Models.Eri_PE1_Cover>("exec Pro_Get_ERI_Cover_Report_PE1 '" + Eri_No + "'").ToList();
    using (ExcelPackage package = new ExcelPackage(templateFile))
    {


    // Ecn_Cover_Sheet for PE1

    ExcelWorksheet worksheet = package.Workbook.Worksheets["(ECN COVER)"];
    string file = this.Request.PhysicalApplicationPath + "Images/images/Koala.jpg";
    Bitmap image = new Bitmap(file);
    ExcelPicture picture = null;
    picture = worksheet.Drawings.AddPicture("pic" , image);
    picture.From.Column = 1;
    picture.From.Row = 8;

    picture.From.ColumnOff = ExcelHelper.Pixel2MTU(2); //Two pixel space for better alignment
    picture.From.RowOff = ExcelHelper.Pixel2MTU(2);//Two pixel space for better alignment
    picture.SetSize(100, 100);

    worksheet.Cells[4, 2].Value = Ecn_Cover_PE1s[0].Eri_No;
    worksheet.Cells[8, 1].Value = Ecn_Cover_PE1s[0].Eri_Content;
    Response.Clear();
    Response.AddHeader("content-disposition", "attachment; filename=" + Eri_No + "_" + DateTime.Today.ToString("yyyymmdd") + ".xlsx");
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.BinaryWrite(package.GetAsByteArray());
    Response.End();
    return null;
    }
    }


    My data of column in database store as below:

    <ol>
    <li style="text-align: center"><u><em><strong><span style="color:#000000"><span class="marker"><span style="background-color:#ff8c00">fdasfasdfdasfdsa</span></span></span></strong></em></u></li>
    <li style="text-align: center"><u><em><strong><span style="color:#000000"><span class="marker"><span style="background-color:#ff8c00">fsdafafdsafds</span></span></span></strong></em></u><br />
    &nbsp;</li>
    </ol>
    <img alt="" src="/Images/images/Koala.jpg" style="float:left; height:150px; width:200px" /><br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    &nbsp;
    <table border="1" cellpadding="1" cellspacing="1" style="width:500px">
    <tbody>
    <tr>
    <td>fasd</td>
    <td>fddfas</td>
    </tr>
    <tr>
    <td>fdafd</td>
    <td>fdas</td>
    </tr>
    <tr>
    <td>fdas</td>
    <td>fdas</td>
    </tr>
    </tbody>
    </table>
    <br />
    &nbsp;


    When i show on View, i can see structure. However i want to export excel save structure display on View.
    How to export above data keep structure of HTML above.
    Monday, January 12, 2015 9:07 PM