简体   繁体   中英

Export table as excel in php

My table has input type text inside td of table, i am getting blank values.Using jquery.table2excel.js to export table. Here is the sample code

<tr>
    <td class="DG_table">
       <span class="left">Total Revenue ($)</span>
    </td>
    <td class="DG_table">
       <input class="form-control" type="text" value="2779695.009431"/>
    </td>
    <td class="DG_table">
       <input class="form-control" type="text" value="2779695.009431"/>
    </td>

</tr>

You have a couple of options, you can convert your data to a CSV, or use the PHPExcel Library

You can put your data into arrays and use the fputcsv function.

CSV Example

$data = array (
    array('row 1 col 1', 'row 1 col 2', 'row 1 col 3'),
    array('row 2 col 1', 'row 2 col 2', 'row 2 col 3'),
    array('row 3 col 1', 'row 3 col 2', 'row 3 col 3'),
);


$file = fopen('mycsv.csv', 'w');

foreach ($data as $cells) {
    fputcsv($file, $cells);
}
fclose($file);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM