我正在使用JQUERY的幫助將腳本導出爲excel的腳本。問題在於,html頁面包含一些帶有重音的西班牙字符,這些字符在Excel文件中沒有正確編碼。但在HTML文件上,他們很好。將html表導出爲使用西班牙字符excel
這裏是我的html頁面的腳本:
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<form action="exporttoexcel.php" method="post"
onsubmit='$("#datatodisplay").val($("<div>").append($("#ReportTable").eq(0).clone()).html())'>
<table id="ReportTable" width="600" cellpadding="2" cellspacing="2" class="myClass">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Country</th>
</tr>
<tr>
<td><center>
investigación
</center></td>
<td><center>
investigación
</center></td>
<td><center>
investigación
</center></td>
</tr>
</table>
<table width="600px" cellpadding="2" cellspacing="2" border="0">
<tr>
<td> </td>
</tr>
<tr>
<td align="center"><input type="hidden" id="datatodisplay" name="datatodisplay">
<input type="submit" value="Export to Excel">
</td>
</tr>
</table>
</form>
和PHP的表單處理代碼如下:解決這種情況
<?php
header("Pragma: no-cache");
header('Content-Encoding: UTF-8');
header('Content-Type: application/force-download; charset=utf-8');
header('Content-disposition: attachment; filename=export.xls');
// Fix for IE bug in download.
header("Pragma: ");
header("Cache-Control: ");
echo $_REQUEST['datatodisplay'];
?>
任何幫助是值得歡迎的。謝謝!
爲什麼不在表單標籤中包含:accept-charset ='utf-8'? – roetnig
相關:[將HTML表格導出到Excel時編碼UTF-8](http://stackoverflow.com/questions/25730008/encoding-utf-8-when-exporting-html-table-to-excel/25730640#25730640) – roetnig