2015-12-13 26 views
13

Próbowałem wyeksportować dane do pliku Excel z numerem QRcode w komórce. Podgasłem i spróbowałem oszukać.phpexcel wstaw QRcode do Excela i zapisz go pod koniec klienta

Wreszcie pomyśleliśmy o dodaniu przykładowego pliku obrazu. następnie z plikiem obrazu phpqrcode.

Wciąż nie udało się, proszę, pomóż mi.

Kod:

/** Error reporting */ 
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'); 

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


// Create new PHPExcel object 
$objPHPExcel = new PHPExcel(); 

$gdImage = imagecreatefromjpeg('abstract_bg.jpg'); 
//Add a drawing to the worksheet 
echo 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__)); 

// Set document properties 
$objPHPExcel->getProperties()->setCreator("Jimson Jose") 
          ->setLastModifiedBy("Jimson Jose") 
          ->setTitle("Office 2007 XLSX Test Document") 
          ->setSubject("Office 2007 XLSX Test Document") 
          ->setDescription("For minimizing work force by jimson, generated using PHP classes.") 
          ->setKeywords("office 2007 openxml php") 
          ->setCategory("Rewards"); 


// Add some data 
$objPHPExcel->setActiveSheetIndex(0) 
      ->setCellValue('A1', 'Hello') 
      ->setCellValue('B2', 'world!') 
      ->setCellValue('C1', 'Hello') 
      ->setCellValue('D2', 'world!'); 

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

// Rename worksheet 
$objPHPExcel->getActiveSheet()->setTitle('Simple'); 


// Set active sheet index to the first sheet, so Excel opens this as the first sheet 
$objPHPExcel->setActiveSheetIndex(0); 


// Redirect output to a client’s web browser (Excel2007) 
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
header('Content-Disposition: attachment;filename="01simple.xlsx"'); 
header('Cache-Control: max-age=0'); 
// If you're serving to IE 9, then the following may be needed 
header('Cache-Control: max-age=1'); 

// If you're serving to IE over SSL, then the following may be needed 
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, 'Excel2007'); 
$objWriter->save('php://output'); 
exit; 
?> 
+0

Wszelkie błędy lub po prostu obraz nie jest wyświetlany? – alalp

+0

Brak błędów wyświetlanych/obserwowanych, ale nie można otworzyć pliku po jego pobraniu. –

+1

Jedną z brakujących rzeczy jest to, że należy wstawić obraz do komórki '$ objDrawing-> setCoordinates ('E1');' – alalp

Odpowiedz

11

Podczas generowania pliku, należy dokonać żadnego wyjścia debugowania jak

echo date('H:i:s') . " Add a drawing to the worksheet\n"; 

ponieważ psuje wyjścia binarnego.

Jeśli usuniesz ten wiersz, twój kod będzie działał.

<?php 
/** Error reporting */ 
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'); 

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


// Create new PHPExcel object 
$objPHPExcel = new PHPExcel(); 

$gdImage = imagecreatefromjpeg('abstract_bg.jpg'); 
//Add a drawing to the worksheet 

$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__)); 

// Set document properties 
$objPHPExcel->getProperties()->setCreator("Jimson Jose") 
          ->setLastModifiedBy("Jimson Jose") 
          ->setTitle("Office 2007 XLSX Test Document") 
          ->setSubject("Office 2007 XLSX Test Document") 
          ->setDescription("For minimizing work force by jimson, generated using PHP classes.") 
          ->setKeywords("office 2007 openxml php") 
          ->setCategory("Rewards"); 


// Add some data 
$objPHPExcel->setActiveSheetIndex(0) 
      ->setCellValue('A1', 'Hello') 
      ->setCellValue('B2', 'world!') 
      ->setCellValue('C1', 'Hello') 
      ->setCellValue('D2', 'world!'); 

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

// Rename worksheet 
$objPHPExcel->getActiveSheet()->setTitle('Simple'); 


// Set active sheet index to the first sheet, so Excel opens this as the first sheet 
$objPHPExcel->setActiveSheetIndex(0); 


// Redirect output to a client’s web browser (Excel2007) 
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
header('Content-Disposition: attachment;filename="01simple.xlsx"'); 
header('Cache-Control: max-age=0'); 
// If you're serving to IE 9, then the following may be needed 
header('Cache-Control: max-age=1'); 

// If you're serving to IE over SSL, then the following may be needed 
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, 'Excel2007'); 
$objWriter->save('php://output'); 
exit; 
?> 

Polecam również usuwanie raportów z tego skryptu błąd:

/** Error reporting */ 
error_reporting(E_ALL); 
ini_set('display_errors', TRUE); 
ini_set('display_startup_errors', TRUE); 
+0

To prawda, gdy, jak w tym przykładzie, wypiszesz plik do php: // output; Jeśli plik xls jest zapisany na dysku, informacje o debugowaniu mogą być obecne –