Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert table html to Excel in javascript

I have a problem to convert an HTML table to an Excel file. I use

window.open ('data: application / vnd.ms-excel,' + ...

in javascript to perform this conversion. The problem is that the Excel file generated only has a one cell with all the HTML code inside. I need a typical table with rows and columns in Excel.

Thanks in advance and greetings to the community. I am super newbie ... please be patient! ;)

JAVASCRIPT CODE:

function excelSeguimientos() {
window.open('data:application/vnd.ms-excel,' + $('#tablaSeguimientos').html());
e.preventDefault();
}

HTML CODE (TABLE):

<table width="1000" id="tablaSeguimientos">
        <tr bgcolor="#CCC">
          <td width="100">Fecha</td>
          <td width="700">Seguimiento</td>
          <td width="170">Producto</td>
          <td width="30">&nbsp;</td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td><?php                 
                $date = date_create($row_Recordset3['fecha']);
                echo date_format($date, 'd-m-Y');
                ?></td>
          <td><?php echo $row_Recordset3['descripcion']; ?></td>
          <td><?php echo $row_Recordset3['producto']; ?></td>
          <td><img src="borrar.png" width="14" height="14" class="clickable" onClick="eliminarSeguimiento(<?php echo $row_Recordset3['idSeguimiento']; ?>)" title="borrar"></td>
        </tr>
      </table>

Thanks for all!!

NOTE: Is it possible to remove automatic the column with the image? Because the table is autogenerated by a mysql query, and has many rows! Thanks!

like image 536
Xavi Gómez Canals Avatar asked Apr 23 '14 11:04

Xavi Gómez Canals


People also ask

How to convert (export) HTML table to excel using JavaScript?

Here Mudassar Ahmed Khan has explained with an example, how to convert (export) HTML Table to Excel file using JavaScript. Using plain JavaScript it is not possible to convert HTML Table to Excel and hence this article will use how to convert (explain) HTML Table to Excel file with the help of the jQuery table2excel plugin.

How to export HTML table from HTML markup to JavaScript?

The following HTML Markup consists of an HTML Table and a Button. When the Export Button is clicked, the JavaScript Export function gets called. Inside the Export function, the jQuery table2excel plugin is applied to the HTML Table.

How to use jQuery table2excel plugin with HTML table?

Inside the Export function, the jQuery table2excel plugin is applied to the HTML Table. The jQuery table2excel plugin accepts filename parameter which sets the name of the Excel file.

How do I send an HTML file to excel?

If the producer of HTML file is you, then you can write an HTTP handler to create an Excel document on the server (which is much more easier than in JavaScript) and send a file to the client.


1 Answers

here is article Export html table to excel using javascript

http://www.codeproject.com/Questions/433079/Export-html-table-to-excel-using-javascript

like image 159
Gaurang s Avatar answered Sep 28 '22 09:09

Gaurang s