How to recover data from an html form and upload to an MS Excel file?

Asked

Viewed 367 times

0

I need to recover data from an HTML form and send to an Excel file, there is some way with Javascript or PHP?

2 answers

1

0

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

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

Browser other questions tagged

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