我正在尝试创建Excel文件并从网页向其附加数据。 Excel文件已创建更正并且数据也保存在其中,但是当我尝试再次加载文件并将数据附加到该文件时。它给出致命错误
未捕获的异常'PHPExcel_Writer_Exception',消息'File 邮编:///home/timespk/public_html/htmlParser/index.xlsx#xl/media/b1b39dadf76812b4c58e06ea6ddf57841.png 不存在' /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007/ContentTypes.php:216 堆栈跟踪:#0 /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007/ContentTypes.php(164): PHPExcel_Writer_Excel2007_ContentTypes-> _getImageMimeType( '拉链:///家/添...')
1 /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007.php(224):
PHPExcel_Writer_Excel2007_ContentTypes-> writeContentTypes(对象(PHPExcel), false)#2 /home/timespk/public_html/htmlParser/index.php(216): PHPExcel_Writer_Excel2007-> save('/ home / timespk / p ...')#3 {main}抛出 在 /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007/ContentTypes.php 在第216行
谁能告诉我这里做错了什么?
答案 0 :(得分:1)
这是我用来将图像保存到Excel文件的代码
$objPHPExcel2->getActiveSheet()->getColumnDimension('A')->setWidth(22);
$image = file_get_contents($imgSrc);
file_put_contents('image' . $highestRow . '.jpg', $image);
$gdImage = imagecreatefromjpeg('image' . $highestRow . '.jpg');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('A'. $highestRow);
$objDrawing->setWorksheet($objPHPExcel2->getActiveSheet());
答案 1 :(得分:0)
我相信我找到了适合PHPExcel_Worksheet_Drawing
的问题的正确解决方案:
https://stackoverflow.com/a/23951597/925196