-2
Guys, I have a code that exports my table from the database perfectly, but it exports it in excel 97 (2003), does anyone know any way to export this table in another version of excel and the file in xlsx instead of xls? NOTE: I already tried to change the file extension to xlsx and gives error when opening the file.
Code:
<?php
include('conexao.php');
error_reporting(0);
$tabela = '<table border="1">';
$tabela .= '<tr>';
$tabela .= '<td><b>Codigo Prova</b></td>';
$tabela .= '<td><b>Nome</b></td>';
$tabela .= '<td><b>Supervisor</b></td>';
$tabela .= '<td><b>Local</b></td>';
$tabela .= '<td><b>Data</b></td>';
$tabela .= '<td><b>Questao 1</b></td>';
$tabela .= '<td><b>Questao 2</b></td>';
$tabela .= '<td><b>Questao 3</b></td>';
$tabela .= '<td><b>Questao 4</b></td>';
$tabela .= '<td><b>Questao 5</b></td>';
$tabela .= '<td><b>Questao 6</b></td>';
$tabela .= '<td><b>Questao 7</b></td>';
$tabela .= '<td><b>Questao 8</b></td>';
$tabela .= '<td><b>Questao 9</b></td>';
$tabela .= '<td><b>Questao 10</b></td>';
$tabela .= '<td><b>Aprovado ou Reprovado</b></td>';
$tabela .= '<td><b>Prova</b></td>';
$tabela .= '<td><b>Numero Acertos</b></td>';
$tabela .= '<td><b>Numero Erros</b></td>';
$tabela .= '</tr>';
$result = "SELECT * FROM provas";
$result_busca = mysqli_query($conn, $result);
$contar = mysqli_num_rows($row_busca);
while($row_busca = mysqli_fetch_array($result_busca)){
$tabela .= '<tr>';
$tabela .= '<td>'.$row_busca['cd_prova'].'</td>';
$tabela .= '<td>'.$row_busca['nome'].'</td>';
$tabela .= '<td>'.$row_busca['supervisor'].'</td>';
$tabela .= '<td>'.$row_busca['local'].'</td>';
$tabela .= '<td>'.$row_busca['data'].'</td>';
$tabela .= '<td>'.$row_busca['questao1'].'</td>';
$tabela .= '<td>'.$row_busca['questao2'].'</td>';
$tabela .= '<td>'.$row_busca['questao3'].'</td>';
$tabela .= '<td>'.$row_busca['questao4'].'</td>';
$tabela .= '<td>'.$row_busca['questao5'].'</td>';
$tabela .= '<td>'.$row_busca['questao6'].'</td>';
$tabela .= '<td>'.$row_busca['questao7'].'</td>';
$tabela .= '<td>'.$row_busca['questao8'].'</td>';
$tabela .= '<td>'.$row_busca['questao9'].'</td>';
$tabela .= '<td>'.$row_busca['questao10'].'</td>';
$tabela .= '<td>'.$row_busca['status_aluno'].'</td>';
$tabela .= '<td>'.$row_busca['tipo_prova'].'</td>';
$tabela .= '<td>'.$row_busca['numero_acertos'].'</td>';
$tabela .= '<td>'.$row_busca['numero_erros'].'</td>';
$tabela .= '</tr>';
}
$tabela .= '</table>';
$arquivo = 'prova.xls';
header ('Cache-Control: no-cache, must-revalidate');
header ('Pragma: no-cache');
header('Content-Type: application/x-msexcel');
header ("Content-Disposition: attachment; filename=\"{$arquivo}\"");
echo $tabela;
?>
Changing the file extension does not really modify its type, if you want to change the file format you should study how it works and adapt its code with differences from the current one. You can also use some library that facilitates this process
– Costamilam
This is not EXCEL is an HTML that coincidentally has a reasonable support in Office programs like Msexcel, but it is not actually excel, neither XLS nor XLSX, it is only HTML, so it has no version. No use for an extension and to believe that the content will change, the extension is only a facilitator for the operating systems, as another example would not be useful to rename a PNG to JPG will not make the image in the format "JPEG" (I refer to the content)
– Guilherme Nascimento