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

Asked

Viewed 307 times

7

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

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

inserir a descrição da imagem aqui

  • 1

    take a look at this site and see if it helps you. http://www.fatbellyman.com/webstuff/xml_to_html/

  • It doesn’t help much because in my case is excel file extension xls...

  • Sorry, I didn’t quite understand your doubt. You today export XLS to HTML manually?

  • Yeah, I was wondering if there’s a way to do it by code...

  • I don’t understand why you do this via PHP. Does the user use a website, or does he use Excel directly? Your question could be clearer.

  • My question is to make the process easier, since the system I created, takes the html file, and makes the clippings of the newsletters, which are in these various files. The system identifies, the name of the Ln according to the bank, and cuts from the starting table at the end of a single student’s report card individually. However, I did the system to upload these multiple files like this in the photo, but whoever is using the system found it difficult, because they have to export the file first and upload all the files. To send the xls file, and to do these exports by code would facilitate...

Show 1 more comment

1 answer

3


Phpexcel

Download the class on github repository.

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


Example of use

Here is done the reading of that 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 whole API phpexcel.

  • Perfect Friend, I took a long time to test because I was working on another project, and I would comment on what was missing, but you edited and put it right. That’s the answer I’ve been waiting for :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.