Convert Excel (.xls) to (.htm)?

7

I made a system for a school, where from the Excel file, where all school bulletins are stored, I export to .htm , where it generates some files with this extension and from there I can make the cut of the bulletins and comparing them with the names of the students who are in the database. However, I wanted to do this export process automatically. Is it possible to perform this operation?

The image below is the files generated after exporting an Excel file ( .xls ). In the case there are several such files, because the source file, in the excel format, had several "navigation guides". And the content of these files is the format .html traditional ...

    
asked by anonymous 21.12.2016 / 15:57

1 answer

3

PHPExcel

Download the class from the GitHub repository .

The php class and its dependencies are in the Classes folder.

Example usage

Here is read from this spreadsheet and generated a table in HTML .

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    require('Classes/PHPExcel/IOFactory.php');

    $arquivo = 'exemplo.xls';

    $tipo = PHPExcel_IOFactory::identify($arquivo);
    $objReader = PHPExcel_IOFactory::createReader($tipo);
    $objPHPExcel = $objReader->load($arquivo);

    $planilha = $objPHPExcel->getSheet(0);
    $ultimaLinha = $planilha->getHighestRow();
    $ultimaColuna = $planilha->getHighestColumn();

    // gera o html
    $html = "<table>";

    // loop em todas as linhas
    for ($linha = 1; $linha <= $ultimaLinha; $linha++) {
        $html .= "<tr>";

        // obtem todos os campos da linha
        $camposLinha = $planilha->rangeToArray("A$linha:$ultimaColuna$linha", NULL, TRUE, FALSE);
        $camposLinha = $camposLinha[0];

        // loop em todos os campos da linha
        for ($campo = 0; $campo < count($camposLinha); $campo++) {
            $html .= "<td>" . $camposLinha[$campo] . "</td>";
        }

        $html .= "</tr>";
    }

    $html .= "</table>";

    // convertendo para HTML.

    $handle = fopen("exemplo.html", "w");
    fwrite($handle, $html);
    fclose($handle);
?>

Here you can see the entire API of PHPExcel.

    
23.12.2016 / 16:11