[英]PHPSpreadsheet xls saving
我必須生成並通過curl將xls文件發布到服務器。 我只是從db獲取數據,制作該文件的第一個版本並將其保存在我的服務器上,然后讀取並通過curl將其發布到遠程服務器。
顯然我在遠程服務器上對該文件的驗證存在一些問題,該腳本讀取了實際上不存在的標題列。
使用Microsoft Excel打開文件,只需按保存並關閉即可解決該問題,但這不是一個可行的選擇。
你能提出一些不同的建議嗎? 這是我生成文件的代碼
$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);
不好意思,但是我認為最好的解決方案是使用tmpfile()
:
$temp = tmpfile();
fwrite($temp, $result);
fseek($temp, 0);
fclose($temp);
它與PHPSpreadSheet庫一起使用。 下一個到達這里的解決方案,因為它處於PHPSpreadSheet搜索的頂部。
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.