Export HTML Table Image to EXCEL or PDF

Asked

Viewed 453 times

0

I have an HTML table, in the last column an image is displayed (JPEG, PNG). Is it possible to export this table to EXCEL or PDF with the image? I used Datatables to do a test, however, the image is not exported along with the table.

<!DOCTYPE html>
<html>
<head>
	<title>Export DataTable</title>
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css">
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.bootstrap4.min.css">
    
</head>
<body>
<table id="example" class="table table-striped table-bordered" style="width:80%; margin: 10px auto;">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
                <th>Imagem</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
                <td><img src="https://www.supercarros.cc/uploads/default/files/unidade/3/foz_img_1.jpg" height="100px"></td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
                <td><img src="http://www.imagenswiki.com/Uploads/imagenswiki.com/ImagensGrandes/imagens-motos-honda.jpg" height="100px"></td>
            </tr>
            <tr>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>66</td>
                <td>2009/01/12</td>
                <td>$86,000</td>
                <td><img src="http://fotos.jornaldocarro.estadao.com.br/uploads/2017/09/30172748/Hennessey-Venom_GT-2011-1280-05-1160x709.jpg" height="100px"></td>

            </tr>
        </tbody>
    </table>

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.bootstrap4.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.colVis.min.js"></script>

    <script type="text/javascript">
    	
    	$(document).ready(function() {
    		var table = $('#example').DataTable( {
    			lengthChange: false,
    			buttons: [ 'copy', 'excel', 'pdf']
    		} );

    		table.buttons().container()
    		.appendTo( '#example_wrapper .col-md-6:eq(0)' );
    	} );

    </script>

</body>
</html>

  • I use a plugin to facilitate, I left the example to download the link below Download the files Example link

  • http://www.randrade.net/2016/05/26/convertendo-tabelas-html-em-arquivos-excel-no-front-end/#disqus_thread Maybe this link will help you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.