使用以下代码,我想打开现有的Excel工作表:
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$inputFileName = $_SERVER['DOCUMENT_ROOT'].$my_file;
$spreadsheet = $reader->load($inputFileName);
$sheet = $spreadsheet->getActiveSheet();
// ...Here i fill out some cells
// And then save the file with the same name (to overwrite)
$writer = new Xlsx($spreadsheet);
$writer->save($inputFileName);
但是会显示以下错误消息:
Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Writer\Exception:
File zip:///[...]/output/ciclo_pm_3_71_285_395.xlsx#xl/media/image1.jpeg
does not exist in [...]/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet
/Writer/Xlsx/ContentTypes.php:186 Stack trace: #0 [...]/vendor/phpoffice
/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php(126):
PhpOffice\PhpSpreadsheet\Writer
\Xlsx\ContentTypes->getImageMimeType('zip:///www/htdo...') #1 /[...]
/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php(223):
PhpOffice\PhpSpreadsheet\Writer
\Xlsx\ContentTypes->writeContentTypes(Object(PhpOffice\PhpSpreadsheet
\Spreadsheet), false) #2 [...]/ajax_stueli_einlesen.php(350):
PhpOffice\PhpSpreadsheet\Writer\Xlsx->save('/www/htdocs/w00...') #3 {main}
thrown in [...]/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer
/Xlsx/ContentTypes.php on line 186
当我从Excel工作表中删除图像时,它可以工作。 故障似乎发生在(写)文件上。 为什么PHPSpreadsheet说"文件不存在"?该文件是Excel工作表的一部分,因此它存在,不是吗?
我无助...... ;-( 任何人都可以帮助我吗?
答案 0 :(得分:0)
我对PhpOffice\PhpSpreadsheet
软件包的最新版本有非常相同的问题。
事实证明,正如丹尼尔(Daniel)所建议的那样,该问题发生了,因为我正试图覆盖模板电子表格。
创建一个新的问题后,问题就消失了。