-1
Ich habe viel Zeit mit stackoverflow und anderen Internetquellen verbracht, um eine Antwort auf diese Frage zu finden. Aber ich konnte keine Lösungen in meinen aktuellen Code umwandeln (das ist sehr wichtig). Also ich habe den Code unten:Html nach Excel. Wie exportiere ich HTML über JS mit utf-8?
var data_type = 'data:application/vnd.ms-excel/charset=UTF-8';
var tables_divs_sum_html = '<table border=1 ><tbody ><tr border=1 ><td border=1 >';
var table_divs = document.getElementsByClassName('calculate--container')
for (let i=0;i<table_divs.length;i++)
{
if (i === table_divs.length - 1)
{
tables_divs_sum_html += table_divs[i].outerHTML + '</td></tr></tbody></table>';
}
else
{
tables_divs_sum_html += table_divs[i].outerHTML + '</td><td>';
}
}
var table_html = tables_divs_sum_html.replace(/ /g, '%20');
var a = document.createElement('a');
a.href = data_type + ', ' + table_html
a.download = `Report_for_${this.props.match.params.month}_${this.props.match.params.year}` + '.xls';
a.click();
<div class="calculate--container">
<h5 style="color: skyblue;">
</h5>
<div class="calculate--table">
<table>
<tbody>
<tr>
<th style="border-top-color: skyblue; border-left-color: skyblue; border-right-color: skyblue; color: skyblue;">
<span>
<span>
July
</span>
2017
</span>
<span>
<br>
<span>
Equality period
</span>
(4)
</span>
</th>
<th colspan="3" style="border-top-color: whitesmoke; border-left-color: whitesmoke; border-right-color: whitesmoke;">
Laborable, de 6 AM a 6 PM
</th>
<th colspan="3" style="border-top-color: whitesmoke; border-left-color: whitesmoke; border-right-color: whitesmoke;">
Fin de semana, de 6 AM a 6 PM
</th>
</tr>
<tr>
<th>
Sensors
</th>
<th>
<span>
ATT
</span>
</th>
<th>
<span>
ATT SLA
</span>
</th>
<th>
<span>
ATT MI
</span>
</th>
<th>
<span>
ATT
</span>
</th>
<th>
<span>
ATT SLA
</span>
</th>
<th>
<span>
ATT MI
</span>
</th>
</tr>
<tr>
<td>
Salvador Orozco Loreto s/n
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
Chapala - Guadalajara & Oleoducto
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
Calz. Jesús González Gallo 655
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
Av. Niños Héroes 642
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
1006 - Niños Héroes 1092
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
Av San Rafael 403
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
Glorieta del Charro
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
1085 - Av del Chamizal 389-333
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
1004 - Felipe Angeles 391
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
1007 - Artesanos 1078
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<td>
1007 - Artesanos 1078
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
<td style="background-color: white; color: black;">
-
</td>
</tr>
<tr>
<th>
<span>
Route
</span>
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
</tr>
<tr class="stupid-height">
</tr>
<tr>
<th style="border-top-color: whitesmoke; border-left-color: whitesmoke;">
<nbsp></nbsp>
</th>
<th>
<span>
AV
</span>
</th>
<th>
<span>
SLA
</span>
</th>
<th>
<span>
MI
</span>
</th>
<th>
<span>
AV
</span>
</th>
<th>
<span>
SLA
</span>
</th>
<th>
<span>
MI
</span>
</th>
</tr>
<tr>
<th>
<span>
Average pass frequency
</span>
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
</tr>
<tr>
<th>
<span>
Number of buses
</span>
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
<th style="color: black;">
-
</th>
<th style="background-color: white; color: black;">
-
</th>
</tr>
<tr class="stupid-height">
</tr>
</tbody>
</table>
</div>
</div>
Die Javascript nach beginnt die Taste auf page.But klicken
Bitte geben Sie spezifischere, was Sie erreichen müssen, oder vielleicht, warum diese benötigen. Um den Inhalt eines HTML-DOMs in eine Excel-Datei zu bekommen, würde ich die Verwendung von CSV empfehlen. Das Format einer echten Excel-Datei selbst ist sehr schwer über Code zu generieren. – Efrain