【发布时间】:2017-11-28 07:32:50
【问题描述】:
我在从 html 表中导出图像时遇到了一些问题。当我单击导出按钮以将 html 表下载为 excel 文件时。下载的 xls 文件具有不同大小的图像。我想以 html 表中的大小导出图像。
我正在使用以下代码,请就问题提出适当的建议。任何其他建议也很有帮助。
<style>
table,th,td
{
border:2px solid red;
border-collapse:collapse;
}
</style>
</head>
<body>
<br/>
<br/>
<div id="divTable">
<center>
<table>
<caption>Person Information</caption>
<tr>
<th>Name</th>
<th>Gender</th>
<th>contact</th>
<th>Image</th>
</tr>
<tr>
<td rowspan="4"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3rlUFLRgsZ9kWB2DHyelOZdsRn6vXm2HlXKULG5qfYQZVYSrClw" alt="Flowers in Chania" width="80px" height="80px"></td>
<td >Male</td>
<td>7665716415</td>
<td>image</td>
</tr>
<tr>
<td >Male</td>
<td>7665716415</td>
<td>image</td>
</tr>
<tr>
<td >Male</td>
<td>7665716415</td>
<td><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS58D5NJFzmB2W_6tdzSVIJdHd8o_aACbV2Dh5AUHbODb62Q0r8Ew" alt="Abdevilliers" width="50px" height="50px"></td>
</tr>
<tr>
<td colspan="2">Male</td>
<td>image</td>
</tr>
</table>
</center>
</div>
<br/>
<br/>
<center>
<button id="myButton">Export Table data into Excel</button>
</center>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$("#myButton").click(function() {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#divTable').html()));
});
</script>
</body>
</html>
提前致谢。
【问题讨论】:
标签: javascript jquery html angularjs excel