Ich versuche Excel-Datei zu generieren, nachdem die Schaltfläche geklickt wird. Ich habe es als Form:Sonderbare Symbole nach dem Generieren Excel-Datei aus HTML-Tabelle
<form method="post" action="ExcelStudio.php" target="_blank" style="float:right;">
<input type="submit" name="export_excel_studio" class="button" value="Studio Report"></input>
</form>
So nach Formular Ich gehe zur Erzeugung von Excel-Datei:
<?php
require_once ('PHPExcel/Classes/PHPExcel.php');
header('Content-Type: text/html; charset=utf-8');
include('inc/database_connection.php');
$conn = mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
$output = '';
$conn->set_charset('utf8_unicode_ci');//if not by default
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$F = $objPHPExcel->getActiveSheet();
if(isset($_POST["export_excel_studio"]))
{
// 1.Get data
$sql2 = '
select
p2.proc_leader as username,
max(case when studio = "APEX" then "x" else "" end) as APEX,
max(case when studio = "BASECAMP" then "x" else "" end) as BASECAMP,
max(case when studio = "CANVAS" then "x" else "" end) as CANVAS,
max(case when studio = "HORIZON" then "x" else "" end) as HORIZON,
max(case when studio = "LAUNCHPAD" then "x" else "" end) as LAUNCHPAD,
max(case when studio = "NEBULA" then "x" else "" end) as NEBULA,
max(case when studio = "ORBIT" then "x" else "" end) as ORBIT,
max(case when studio = "PALETTE" then "x" else "" end) as PALETTE,
max(case when studio = "SANDBOX" then "x" else "" end) as SANDBOX,
max(case when studio = "STELLAR" then "x" else "" end) as STELLAR,
max(case when studio = "THE CLIMB" then "x" else "" end) as THECLIMB,
max(case when studio = "TOONIGAMI" then "x" else "" end) as TOONIGAMI,
max(case when studio = "TREEHOUSE" then "x" else "" end) as TREEHOUSE
from process p1
left join (
select *
from proc_leader
union all
select *
from proc_checker
union all
select *
from proc_staff
) p2 on p1.projectNo = p2.projectNo
and p1.process = p2.process
group by p2.proc_leader
';
// 2. Output table
$query2 = mysqli_query($conn, $sql2);
$header = '<th style="border: 1px solid black;">Username</th>
<th style="border: 1px solid black;">Studio APEX</th>
<th style="border: 1px solid black;">Studio BASECAMP</th>
<th style="border: 1px solid black;">Studio CANVAS</th>
<th style="border: 1px solid black;">Studio HORIZON</th>
<th style="border: 1px solid black;">Studio LAUNCHPAD</th>
<th style="border: 1px solid black;">Studio NEBULA</th>
<th style="border: 1px solid black;">Studio ORBIT</th>
<th style="border: 1px solid black;">Studio PALETTE</th>
<th style="border: 1px solid black;">Studio SANDBOX</th>
<th style="border: 1px solid black;">Studio STELLAR</th>
<th style="border: 1px solid black;">Studio THECLIMB</th>
<th style="border: 1px solid black;">Studio TOONIGAMI</th>
<th style="border: 1px solid black;">Studio TREEHOUSE</th>';
$body = '';
while ($data2 = mysqli_fetch_assoc($query2)) {
$username = $data2['username'];
$apex = $data2['APEX'];
$basecamp = $data2['BASECAMP'];
$canvas = $data2['CANVAS'];
$horizon = $data2['HORIZON'];
$launchpad = $data2['LAUNCHPAD'];
$nebula = $data2['NEBULA'];
$orbit = $data2['ORBIT'];
$palette = $data2['PALETTE'];
$sandbox = $data2['SANDBOX'];
$stellar = $data2['STELLAR'];
$theclimb = $data2['THECLIMB'];
$toonigame = $data2['TOONIGAMI'];
$treehouse = $data2['TREEHOUSE'];
$row = '<td style="border: 1px solid black;">' . htmlspecialchars($username) . '</td>
<td style="border: 1px solid black;">' . $apex . '</td>
<td style="border: 1px solid black;">' . $basecamp . '</td>
<td style="border: 1px solid black;">' . $canvas . '</td>
<td style="border: 1px solid black;">' . $horizon . '</td>
<td style="border: 1px solid black;">' . $launchpad . '</td>
<td style="border: 1px solid black;">' . $nebula . '</td>
<td style="border: 1px solid black;">' . $orbit . '</td>
<td style="border: 1px solid black;">' . $palette . '</td>
<td style="border: 1px solid black;">' . $sandbox . '</td>
<td style="border: 1px solid black;">' . $stellar . '</td>
<td style="border: 1px solid black;">' . $theclimb . '</td>
<td style="border: 1px solid black;">' . $toonigame . '</td>
<td style="border: 1px solid black;">' . $treehouse . '</td>';
$body .= "<tr style='border: 1px solid black;'>$row</tr>";
}
$output .= "
<table class='table' style='border: 1px solid black;'>
<thead><tr>$header</tr></thead>
<tbody>$body</tbody>
</table>
";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="StudioReport.xls"');
header('Cache-Control: max-age=0');
echo $output;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
Es ausgenommen eine Sache gut funktioniert, ich habe seltsame Symbole nach Tabelle. Also denke ich, dass es irgendwo ein Problem gibt. Hier ist, was ich nach dem Öffnen der Excel-Datei bekommen habe. Was könnte ein Problem sein und wie kann ich das lösen? Danke
Denken Sie daran, 'Header zu verwenden ('Content-Type: text/html; charset = utf-8');' auch, vielleicht, dass etwas zu machen. – LordNeo
@LordNeo hat nicht geholfen –
Entweder senden Sie die Datei an den Browser, ___ or___ send html Markup; aber nicht beides .... der Browser (und das http-Protokoll) kann nur auf Anfrage antworten –