2014-12-31 19 views
16

Ben örnek alıyorum içinde phpexcel içinde Excel'e Resim Eklenmesi, bununla bıktım.Sadece GET Metodu içinde geçen değeri ile çalıştı <a href="https://phpexcel.codeplex.com/">phpexcel</a></p> <p>dan php

Şimdi a3 kolonuna resim eklemeye çalışıyorum.

Referans Kodu:

<?php 
$value = $_GET['value']; 
error_reporting(E_ALL); 
ini_set('display_errors', TRUE); 
ini_set('display_startup_errors', TRUE); 
date_default_timezone_set('Europe/London'); 

if (PHP_SAPI == 'cli') 
    die('This example should only be run from a Web Browser'); 

require_once dirname(__FILE__) . '/Classes/PHPExcel.php'; 


$objPHPExcel = new PHPExcel(); 


$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") 
          ->setLastModifiedBy("Maarten Balliauw") 
          ->setTitle("Office 2007 XLSX Test Document") 
          ->setSubject("Office 2007 XLSX Test Document") 
          ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") 
          ->setKeywords("office 2007 openxml php") 
          ->setCategory("Test result file"); 


$objPHPExcel->setActiveSheetIndex(0) 
      ->setCellValue('A1', $value) 
      ->setCellValue('B2', 'world!') 
      ->setCellValue('C1', 'Hello') 
      ->setCellValue('D2', 'world!'); 


$objPHPExcel->setActiveSheetIndex(0) 
      ->setCellValue('A4', 'Miscellaneous glyphs') 
      ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); 

$objPHPExcel->getActiveSheet()->setTitle('Simple'); 


$objPHPExcel->setActiveSheetIndex(0); 
header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="01simple.xls"'); 
header('Cache-Control: max-age=0'); 
header('Cache-Control: max-age=1'); 

header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past 
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified 
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 
header ('Pragma: public'); // HTTP/1.0 

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
$objWriter->save('php://output'); 
exit; 
?> 

Örnek Kod ekleme görüntü için:

$gdImage = imagecreatefromjpeg('images/officelogo.jpg'); 
// Add a drawing to the worksheetecho date('H:i:s') . " Add a drawing to the worksheet\n"; 
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing(); 
$objDrawing->setName('Sample image');$objDrawing->setDescription('Sample image'); 
$objDrawing->setImageResource($gdImage); 
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG); 
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT); 
$objDrawing->setHeight(150); 
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); 

Ama a3 kolonununda veya başka bir kolonununda içinde jpg eklemek nasıl anlamak yok aldığım excel dosyasında.

Bunu nasıl yapabilirim? Görüntü yardımcı olabilir için bir resim hücre// sütun içinde olmadığını

$objDrawing->setCoordinates('A3'); 

Not örneklerde olduğu ve belgeleri olarak

+0

tam kodu için lütfen ziyaret edin: - http://www.7logic.info/2017/04/convert-excel -plus-image-to-pdf-using.html – Akshath

cevap

14

Belirleme, koordinatlar, ancak fazla üst üste bu hücrenin/sütunun/satırın

+0

Teşekkürler efendim, Ama bunu laravel uygulamasında buna dahil ederken ** require_once base_path(). '\ public \ assets \ excel \ Classes \ PHPExcel.php'; * * PHPExcel'i yeniden sınıflandıramayan bir hata gösteriyor – AngularAngularAngular

+0

Bu bana, PHPExcel.php ** sınıfı PHPExcel {** siyah ekranındaki satırı işaret ediyor. – AngularAngularAngular

+1

Bu hata, orijinal sorunuzun sorduğu şey değil. Eğer Laravel kullanıyorsanız, neden PHPExcel –

4

aynı pozisyonda ana levha makalemi okuyun

http://www.7codes.info/post/8/export-excel-files-with-images-using-php-excel-library

$objDrawing = new PHPExcel_Worksheet_Drawing(); //create object for Worksheet drawing 
$objDrawing->setName('Customer Signature');  //set name to image 
$objDrawing->setDescription('Customer Signature'); //set description to image 
$signature = $reportdetails[$rowCount][$value]; //Path to signature .jpg file 
$objDrawing->setPath($signature); 
$objDrawing->setOffsetX(25);      //setOffsetX works properly 
$objDrawing->setOffsetY(10);      //setOffsetY works properly 
$objDrawing->setCoordinates($column.$cell);  //set image to cell 
$objDrawing->setWidth(32);     //set width, height 
$objDrawing->setHeight(32); 

$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); //save 
0

kod aşağıda logosu veya görüntüler ekleme/gösteren sorun kullanımını çözmek:

$objDrawing = new PHPExcel_Worksheet_Drawing(); 
$objDrawing->setName('test_img'); 
$objDrawing->setDescription('test_img'); 
$objDrawing->setPath('../images/logo.png'); 
$objDrawing->setCoordinates('A1');      
//setOffsetX works properly 
$objDrawing->setOffsetX(5); 
$objDrawing->setOffsetY(5);     
//set width, height 
$objDrawing->setWidth(100); 
$objDrawing->setHeight(35); 
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); 
İlgili konular