我下载的表只打印标题,不显示任何内容。 我遵循这里的教程:http://webslesson.blogspot.in/2016/02/export-mysql-data-to-excel-in-php-php-tutorial.html
以下插件我尝试过无法渲染我的大量数据 1.clarketm(合并行) 2.(尝试但无法渲染巨大的数据)https://github.com/kayalshri/tableExport.jquery.plugin
我的HTML DOM IS( index.php )
List<String> value = map.get("key");
Set<A> set = null;
if (value != null) {
set = listOfA.stream()
.filter(a->value.stream()
.anyMatch(s->a.getString().equalsIgnoreCase(s)))
.collect(Collectors.toSet());
}
我的 excel.php 文件是
<div id="allTables">
<table border="2" width="100%">
<tr>
<th width="30%">Name</th>
<th width="20%">Activity on Code Project (%)</th>
<th width="10%">Activity on C# Corner (%)</th>
<th width="10%">Activity on Asp Forum (%)</th>
</tr>
<tr>
<td>Sibeesh</td>
<td>100</td>
<td>98</td>
<td>80</td>
</tr>
<tr>
<td>Ajay</td>
<td>90</td>
<td>0</td>
<td>50</td>
</tr>
</table>
</div>
<p id="exportexcel">EXport to Excel</p>
<script>
$(document).ready(function () {
$('#exportexcel').click(function(){
var excel_data = $('#allTables').html();
console.log(excel_data);
var page = "excel.php?data="+excel_data;
console.log(page);
window.location = page; // here iam sending data to excel.php through get method
});
</script>
- 请提前帮助我帮助我做错了
答案 0 :(得分:1)
C#Corner上的活动(%) - 此行中的“#”导致问题。对此进行编码将解决上述代码中的问题。
但建议使用POST更好。
答案 1 :(得分:0)
如果您通过get传递html代码,则必须对其进行编码,否则您可以使用post方法。 以下代码对您有用。
<script type="text/javascript">
var htmlString= document.getElementById(allTables).innerHTML;
$.ajax({
type: "POST",
url: "excel.php",
dataType:'html',// ***add this option!***
data: {html:htmlString},
success: function (data) {
// this is executed when ajax call finished well
alert('file has been saved');
location.reload();
},
error: function (xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0) alert("Error: " + status); // status 0 - when load is interrupted
}
});
}
</script>
您的excel.php文件应为
<?php
header('Content-Type: application/vnd.ms-excel');
header('Content-disposition: attachment; filename='.rand().'.xls');
echo $_POST["html"];
?>
如果您想使用$ _GET,那么您应该参考 how can I javascript decodeURI in PHP? 在javascript中编码和解码uri到php