How to retrieve data from an html form and send it to an MS Excel file?

0

I need to retrieve data from an HTML form and send it to an Excel file, is there anyway with JavaScript or with PHP?

    
asked by anonymous 02.08.2017 / 18:29

2 answers

1

There is a form answered in a StackOverflow post in English. You can adapt the code according to what you want. Follow the link: link

    
02.08.2017 / 19:44
0

To manipulate Excel files in PHP I work with the library csv . To install the package you will need to use composer .

To create a file with this library is very easy.

Create a header

$header = ["nome" , "email", "contato", "messagem", "empresa"];

Your Data

$contents = [
    ['Fulano da Silva', "fulano.silva@...", 9999999999, 'Texto', StackOverflow],
    ['Ciclano da Silva', "ciclano.silva@...", 9999999999, 'Texto', StackOverflow]
];

Calling the library

$writer = Writer::createFromFileObject(new SplTempFileObject());
//Criando um arquivo CSV temporário

$writer->setDelimiter("\t"); //Caracter delimitador
$writer->setNewline("\r\n"); //Forma do windows aplicar o quebra-linha
$writer->setOutputBOM(Writer::BOM_UTF8);
//Saída das informações respeitando os caráteres especiais

$writer->insertOne($header);
$writer->insertAll($contents);

If you want to download the file add the lines

$writer->setEncodingFrom('ISO-8859-15');
$writer->output('firstname.csv');

More information

02.08.2017 / 20:31