我怎样才能将智能表作为 excel 文件并将其放入 PHP 中的 cloudinary?
How can I get a smartsheet as excel file and put it to cloudinary in PHP?
我需要你的帮助来获取 excel 的智能表并将其放入 PHP 中的 cloudinary。
我使用下面的代码。
/**
* @param $sheetId
*/
public function getSheetAsExcel($sheetId)
{
$url = self::SMART_SHEET_BASE_URL . '/sheets/' . $sheetId;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Authorization: Bearer ' . $this->smartsheetCredentials;
$headers[] = 'Accept: application/vnd.ms-excel';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
在cloudinary中创建了一个文件,但是当我下载它时,格式错误。
screenshot of the message shown
$outStream = $this->smartsheetClient->getSheetAsExcel($smart_sheet_id);
$file_name = 'filename.xlsx';
$cloudinarySignature = (new CloudinayClient())->getCloudinarySignature();
$temp = tmpfile();
$path = stream_get_meta_data($temp)['uri'];
fwrite($temp, file_put_contents($path, $outStream));
fseek($temp, 0);
$cloudinaryResponse = \Cloudinary\Uploader::upload($path, [
"public_id" => $file_name,
"resource_type" => "auto",
"signature" => $cloudinarySignature,
"version" => time()
]);
fclose($temp);
我更新了我的代码如下。问题可能出在 tmpfile()。
$file = $this->smartsheetClient->getSheetAsExcel($smart_sheet_id);
$file_name = 'filename.xlsx';
$cloudinarySignature = (new CloudinayClient())->getCloudinarySignature();
$path = self::TMP_FOLDER ."/$file_name";
file_put_contents($path, $file);
$cloudinaryResponse = \Cloudinary\Uploader::upload($path, [
"public_id" => $file_name,
"resource_type" => "auto",
"signature" => $cloudinarySignature,
"version" => time()
]);
unlink($path);
我需要你的帮助来获取 excel 的智能表并将其放入 PHP 中的 cloudinary。 我使用下面的代码。
/**
* @param $sheetId
*/
public function getSheetAsExcel($sheetId)
{
$url = self::SMART_SHEET_BASE_URL . '/sheets/' . $sheetId;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Authorization: Bearer ' . $this->smartsheetCredentials;
$headers[] = 'Accept: application/vnd.ms-excel';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
在cloudinary中创建了一个文件,但是当我下载它时,格式错误。
screenshot of the message shown
$outStream = $this->smartsheetClient->getSheetAsExcel($smart_sheet_id);
$file_name = 'filename.xlsx';
$cloudinarySignature = (new CloudinayClient())->getCloudinarySignature();
$temp = tmpfile();
$path = stream_get_meta_data($temp)['uri'];
fwrite($temp, file_put_contents($path, $outStream));
fseek($temp, 0);
$cloudinaryResponse = \Cloudinary\Uploader::upload($path, [
"public_id" => $file_name,
"resource_type" => "auto",
"signature" => $cloudinarySignature,
"version" => time()
]);
fclose($temp);
我更新了我的代码如下。问题可能出在 tmpfile()。
$file = $this->smartsheetClient->getSheetAsExcel($smart_sheet_id);
$file_name = 'filename.xlsx';
$cloudinarySignature = (new CloudinayClient())->getCloudinarySignature();
$path = self::TMP_FOLDER ."/$file_name";
file_put_contents($path, $file);
$cloudinaryResponse = \Cloudinary\Uploader::upload($path, [
"public_id" => $file_name,
"resource_type" => "auto",
"signature" => $cloudinarySignature,
"version" => time()
]);
unlink($path);