我在很多帖子中看到了這個問題。但沒有人回答。當我在一個Excel文件中插入圖像 第一次,沒有問題是there.but如果我加載的Excel文件再次,並嘗試在另一個單元格中插入其他影像,出現以下問題:PHPExcel - 加載和寫入後嘗試插入圖像時出錯
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'File zip://C:\xampp\htdocs\Well\test.xlsx#xl/media/well1.bmp does not exist' in C:\xampp\htdocs\Well\Classes\PHPExcel\Writer\Excel2007\ContentTypes.php:242 Stack trace: #0 C:\xampp\htdocs\Well\Classes\PHPExcel\Writer\Excel2007\ContentTypes.php(181): PHPExcel_Writer_Excel2007_ContentTypes->_getImageMimeType('zip://C:\xampp\...') #1 C:\xampp\htdocs\Well\Classes\PHPExcel\Writer\Excel2007.php(246): PHPExcel_Writer_Excel2007_ContentTypes->writeContentTypes(Object(PHPExcel), false) #2 C:\xampp\htdocs\Well\test.php(125): PHPExcel_Writer_Excel2007->save('test.xlsx') #3 {main} thrown in C:\xampp\htdocs\Well\Classes\PHPExcel\Writer\Excel2007\ContentTypes.php on line 242.
這是我的代碼得出:
`$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('image');
$objDrawing->setDescription('nnnnn');
$objDrawing->setPath('images/well.bmp');
$objDrawing->setCoordinates('I'.$s);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());`
我搜索很多,我看到關於它的一些職位。但沒有人回答。
編輯: 我的代碼:
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/IOFactory.php';
$name='statistics.xlsx';
if(file_exists($name))
{
$objPHPExcel = PHPExcel_IOFactory::load($name);
$lastRow = $objPHPExcel->getActiveSheet()->getHighestRow();
$j=$lastRow+10;
}
else
{
$j=1;
$objPHPExcel = new PHPExcel();
}
$i='A';
$objPHPExcel->setActiveSheetIndex(0);
// I am not writing the entire data
$objPHPExcel->getActiveSheet()->setCellValue($i++.$j, 'name');
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('image');
$objDrawing->setDescription('image');
$objDrawing->setPath('image.png');
$objDrawing->setCoordinates('E'.$s);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($name);
您能否將詳細說明如何複製此錯誤發佈您的整個代碼? –
@Grzegorz ...感謝您的回覆。我已經包含了整個代碼。請檢查一下。第一次儲存時沒問題。但是當我第二次嘗試時,它顯示錯誤並刪除保存的文件。請考慮一下。 – user3673501