Excel Exporting Template

Exporting text with template

Sales report

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

    <div cell="A1" range="A1:H1" excelStyle='<?php echo json_encode($styleArray); ?>' >
        Sales Report
    </div>

    <div range="A2:H2">
        <?php
        \koolreport\Excel\Text::create(array(
            "text" => 'Sales Report',
            "excelStyle" => $styleArray
        ));
        ?>
    </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;
    use \koolreport\excel\BigSpreadsheetExportable;

    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 Template</h1>
        <p class="lead">Exporting text with template</p>
		<form method="post">
			<button type="submit" class="btn btn-primary" formaction="export.php?type=excel">Download Excel</button>
			<button type="submit" class="btn btn-primary" formaction="export.php?type=bigspreadsheet">Download Big Spreadsheet</button>
		</form>			

	</div>
	<div class='box-container'>
		<div>
			Sales report
		</div>
	</div>
</div>
<?php
    $sheet1 = "Sales by Customer";
?>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="Excel,HTML,CSS,XML,JavaScript">
<meta name="creator" content="John Doe">
<meta name="subject" content="subject1">
<meta name="title" content="title1">
<meta name="category" content="category1">

<?php
$styleArray = [
    'font' => [
        'name' => 'Calibri', //'Verdana', 'Arial'
        'size' => 40,
        'bold' => true,
        'italic' => FALSE,
        'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
        'strikethrough' => FALSE,
        'superscript' => false,
        'subscript' => false,
        'color' => [
            'rgb' => '0000FF', //blue color
            // 'argb' => 'FF000000',
        ]
    ],
    'alignment' => [
        'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
        'vertical' => 'bottom',//top, center, justify, distributed
        'textRotation' => 0,
        'wrapText' => false,
        'shrinkToFit' => false,
        'indent' => 0,
        'readOrder' => 0,
    ],
    'borders' => [
        'top' => [
            'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
            'color' => [
                'rgb' => '808080',
                'argb' => 'FF808080',
            ]
        ],
        //left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
    ],
    'fill' => [
        'fillType' => 'none', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
        'rotation' => 90,
        'color' => [
            'rgb' => 'A0A0A0',
            'argb' => 'FFA0A0A0',
        ],
        'startColor' => [
            'rgb' => 'A0A0A0',
            'argb' => 'FFA0A0A0',
        ],
        'endColor' => [
            'argb' => 'FFFFFF',
            'argb' => 'FFFFFFFF',
        ],
    ],
];
?>

<div sheet-name="<?php echo $sheet1; ?>">
    <div cell="A1" range="A1:H1" excelStyle='<?php echo json_encode($styleArray); ?>' >
        Sales Report
    </div>

    <div range="A2:H2">
        <?php
        \koolreport\excel\Text::create(array(
            "text" => 'Sales Report',
            "excelStyle" => $styleArray
        ));
        ?>
    </div>
</div>
<?php
include "MyReport.php";
$report = new MyReport;
$report->run();

$exportType = $_GET["type"];
if ($exportType === "excel") {
    $report->exportToExcel('MyReportExcel')->toBrowser("MyReportExcel.xlsx");
} else {
    $report->exportToXLSX('MyReportExcel')->toBrowser("MyReportBigSpreadsheet.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