I need to retrieve data from an HTML form and send it to an Excel file, is there anyway with JavaScript or with PHP?
I need to retrieve data from an HTML form and send it to an Excel file, is there anyway with JavaScript or with PHP?
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
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