简体   繁体   English

在PHP中将表导出为Excel

[英]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. 我的表在表的td内有输入类型的文本,我得到空值。使用jquery.table2excel.js导出表。 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 您有两种选择,可以将数据转换为CSV,或使用PHPExcel库

You can put your data into arrays and use the fputcsv function. 您可以将数据放入数组并使用fputcsv函数。

CSV Example CSV范例

$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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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