Excel Exporting Image

Exporting excel image with template

This example demonstrates how to export image to an excel file.

    <div range="A2:B2">
        <?php
        \koolreport\excel\Image::create(array(
            'path' => '../../../assets/images/bar.png', // must have

            // "range" => "B2:D4", // overrides width, height if exists
            // 'coordinate' => 'B2', // default: A1
            // 'coordinate2' => 'D4', // default: '', // overrides width, height if exists

            // 'offsetX' => 50, // default: 0
            // 'offsetX2' => 50, // default: 0
            // 'offsetY' => 100, // default: 0
            // 'offsetY2' => 100, // default: 0
            
            // 'width' => 300, // default: 0
            // 'height' => 300, // default: 0
            // 'resizeProportional' => false, // default: true
            
            // 'name' => 'name', // default: ''
            // 'description' => 'description', // default: ''
            // 'roration' => 0, // default: 0
            // 'hyperlink' => null, //Hyperlink object, default: null
            // 'shadow' => null, //Shadown object, default: null
            // 'shadowVisible' => true, // default: false
            // 'shadowDirection' => 45, // default: 0
        ));
        ?>
    </div>
<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
require_once "../../../load.koolreport.php";

use \koolreport\processes\Map;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;

class MyReport extends koolreport\KoolReport
{
    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;

    function settings()
    {
        return array(
            "dataSources" => array(
                "dollarsales"=>array(
                    'filePath' => '../../../databases/customer_product_dollarsales2.csv',
                    'fieldSeparator' => ';',
                    'class' => "\koolreport\datasources\CSVDataSource"      
                ), 
            )
        );
    }    function setup()
    {
        $node = $this->src('dollarsales')
        //->query('select *, dollar_sales as dollar_sales2 from customer_product_dollarsales2')
        ->pipe(new Map([
            '{value}' => function($row, $meta) {
                $row['orderQuarter'] = 'Q' . $row['orderQuarter'];
                return $row;
            },
            '{meta}' => function($meta) {
                $meta['columns']['orderDate']['type'] = 'datetime';
                $meta['columns']['orderQuarter']['type'] = 'string';
                return $meta;
            }
        ]))
        ;

        $node
        ->pipe(new Limit(array(
            50, 0
        )))
        ->pipe(new Map([
            "{meta}" => function($meta) {
                $cMeta = & $meta["columns"]["dollar_sales"];
                $cMeta["footer"] = "sum";
                $cMeta["type"] = "number";
                // print_r($meta); exit;
                return $meta;
            }
        ]))
        ->pipe($this->dataStore('orders'));

        $node->pipe(new Cube(array(
            "rows" => "customerName",
            "column" => "orderQuarter",
            "sum" => "dollar_sales",
        )))
        ->pipe(new Limit(array(
            5, 0
        )))
        ->pipe($this->dataStore('salesQuarterCustomer'));

        $node->pipe(new Cube(array(
            "rows" => "productName",
            "column" => "orderQuarter",
            "sum" => "dollar_sales",
        )))
        ->pipe(new Limit(array(
            5, 0
        )))
        ->pipe($this->dataStore('salesQuarterProduct'));

        $node
        ->pipe(new Filter(array(
            array('customerName', '<', 'Au'),
            array('orderYear', '>', 2003),
        )))
        ->pipe(new Pivot(array(
            "dimensions" => array(
                "column" => "orderYear, orderQuarter",
                "row" => "customerName, productLine",
            ),
            "aggregates" => array(
                "sum" => "dollar_sales",
            ),
        )))
        ->pipe($this->dataStore('salesPivot'));
    }
}
<?php
use \koolreport\pivot\widgets\PivotTable;
use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
	<div style='text-align: center;margin-bottom:30px;'>
        <h1>Excel Exporting Image</h1>
        <p class="lead">Exporting excel image with template</p>
		<form>
			<button type="submit" class="btn btn-primary" formaction="export.php">Download Excel</button>
		</form>
	</div>
	<div class='box-container'>
		<div>
			<img src="../../../assets/images/bar.png" />
		</div>
	</div>
</div>
<?php
    $sheet1 = "Sales by Customer";
?>
<div sheet-name="<?php echo $sheet1; ?>">
    <div range="A1:C5">
        <?php
        \koolreport\excel\Image::create(array(
            'path' => '../../../assets/images/bar.png', // must have

            // "range" => "B2:D4", // overrides width, height if exists
            // 'coordinate' => 'B2', // default: A1
            // 'coordinate2' => 'D4', // default: '', // overrides width, height if exists

            // 'offsetX' => 50, // default: 0
            // 'offsetX2' => 50, // default: 0
            // 'offsetY' => 100, // default: 0
            // 'offsetY2' => 100, // default: 0
            
            // 'width' => 300, // default: 0
            // 'height' => 300, // default: 0
            // 'resizeProportional' => false, // default: true
            
            // 'name' => 'name', // default: ''
            // 'description' => 'description', // default: ''
            // 'roration' => 0, // default: 0
            // 'hyperlink' => null, //Hyperlink object, default: null
            // 'shadow' => null, //Shadown object, default: null
            // 'shadowVisible' => true, // default: false
            // 'shadowDirection' => 45, // default: 0
        ));
        ?>
    </div>
</div>
<?php
include "MyReport.php";
$report = new MyReport;
$report->run();
$report->exportToExcel('MyReportExcel')->toBrowser("MyReport.xlsx");

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro