简体   繁体   中英

PHPSpreadsheet xls saving

I've got to generate and post a xls file to a server via curl. I just get my data from db, make the first version of the file and save it on my server, then read it and post it via curl to the remote server.

Apparently I'm having some issue with the validation of that file on the remote server which script read an header column that actually doesn't exists.

Opening the file with Microsoft Excel, simply pressing save and closing it fix the problem but is not a approachable option.

Can you suggest something different? This is my code generating the file

$dataToExport = $this->db->getAll($query);
$savePath = '/path/to/my/server';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($dataToExport, NULL, 'A1');
$sheet->setTitle("Foglio1");
$writer = new Xls($spreadsheet);
$writer->save($savePath);
$cFile = curl_file_create($savePath);
$post = array('file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL,'http://www.url.to/remote/server');
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);

Sorry for the time, but i think the best solution is to use tmpfile() :

$temp = tmpfile();
fwrite($temp, $result);
fseek($temp, 0);
fclose($temp);

It's work with PHPSpreadSheet Library. Solution for the next ones arriving here, because it was in top position of a PHPSpreadSheet search.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM