Skip to content

Instantly share code, notes, and snippets.

@goelvibhor4
Created June 13, 2016 06:19
Show Gist options
  • Save goelvibhor4/3bae5261179518c049c6ede5795f31ee to your computer and use it in GitHub Desktop.
Save goelvibhor4/3bae5261179518c049c6ede5795f31ee to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
ini_set('include_path', ini_get('include_path').';../Classes/');
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
$excel = new PHPExcel();
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="your_name.xls"');
header('Cache-Control: max-age=0');
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$logo = 'C:\xampp\htdocs\excel\image\logo.png';// Provide path to
$objDrawing->setPath($logo); //setOffsetY has no effect
$objDrawing->setCoordinates('A1');
$objDrawing->setHeight(100);
$objDrawing->setWorksheet($excel->getActiveSheet());
$objDrawing2 = new PHPExcel_Worksheet_Drawing();
$objDrawing2->setName('PHPExcel logo');
$objDrawing2->setDescription('PHPExcel logo');
$objDrawing2->setPath('C:\xampp\htdocs\excel\image\Vibhor_Goel.jpg');
$objDrawing2->setHeight(200);
$objDrawing2->setCoordinates('C10');
$objDrawing2->setOffsetX(10);
$objDrawing2->setWorksheet($excel->getActiveSheet());
$testArray = array(
array ('Invoice no',':'),
array('Invoice Date',':'),
array('Brand Name',':'),
array('Estimate no',':'),
array('Campaign',':')
);
$testArray = array(
array ('Invoice no',':'),
array('Invoice Date',':'),
array('Brand Name',':'),
array('Estimate no',':'),
array('Campaign',':')
);
$testArray2 = array(
array ('Invoice no'),
array('Invoice Date'),
array('Brand Name'),
array('Estimate no'),
array('Campaign')
);
// logo height
$excel->getActiveSheet()->fromArray($testArray, NULL, 'G1');
$excel->getActiveSheet()->fromArray($testArray2, NULL, 'I1');
/*
// Do your stuff here
$excel->getActiveSheet()->setCellValue('G1', 'Invoice no');
$excel->getActiveSheet()->setCellValue('G2', 'Invoice Date');
$excel->getActiveSheet()->setCellValue('G3', 'Brand Name ');
$excel->getActiveSheet()->setCellValue('G4', 'Estimate no');
$excel->getActiveSheet()->setCellValue('G5', 'Campaign ');*/
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$writer->save("excel.xls");
readfile("excel.xls");
/*$sql = "SELECT * FROM my_table";
$result = mysql_query($sql);
$row = 1; // 1-based index
while($row_data = mysql_fetch_assoc($result)) {
$col = 0;
foreach($row_data as $key=>$value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$col++;
}
$row++;
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment