Excel Table Complex Header

Exporting table with complex headers

productName Date dollar_sales
Year Month Day
1937 Lincoln Berline 2003 1 10 3,726.45
1936 Mercedes-Benz 500K Special Roadster 2003 1 10 1,768.33
1952 Alpine Renault 1300 2003 1 29 5,571.80
1962 LanciaA Delta 16V 2003 1 29 5,026.14
1958 Setra Bus 2003 1 29 3,284.28
1940 Ford Pickup Truck 2003 1 29 3,307.50
1926 Ford Fire Engine 2003 1 29 1,283.48
1913 Ford Model T Speedster 2003 1 29 2,489.13
1934 Ford V8 Coupe 2003 1 29 2,164.40
18th Century Vintage Horse Carriage 2003 1 29 2,173.00
1917 Maxwell Touring Car 2003 1 29 3,970.26
1940s Ford truck 2003 1 29 3,530.51
1939 Cadillac Limousine 2003 1 29 1,670.75
1962 Volkswagen Microbus 2003 1 29 3,864.24
1936 Chrysler Airflow 2003 1 29 2,215.50
1980’s GM Manhattan Express 2003 1 29 2,866.25
1996 Peterbilt 379 Stake Bed with Outrigger 2003 1 29 2,850.75
1982 Camaro Z28 2003 1 29 3,950.93
1969 Corvair Monza 2003 1 31 4,468.96
1957 Chevy Pickup 2003 1 31 4,566.99
1998 Chrysler Plymouth Prowler 2003 1 31 3,261.60
1964 Mercedes Tour Bus 2003 1 31 3,559.17
1992 Ferrari 360 Spider red 2003 1 31 3,816.85
1970 Triumph Spitfire 2003 1 31 4,529.60
1970 Dodge Coronet 2003 1 31 1,820.70
1958 Chevy Corvette Limited Edition 2003 1 31 1,338.04
1992 Porsche Cayenne Turbo Silver 2003 1 31 2,767.70
1954 Greyhound Scenicruiser 2003 1 31 1,818.25
1950's Chicago Surface Lines Streetcar 2003 1 31 2,770.95
Diamond T620 Semi-Skirted Tanker 2003 1 31 3,781.47
1962 City of Detroit Streetcar 2003 1 31 1,705.92
1972 Alfa Romeo GTA 2003 2 11 6,392.00
2001 Ferrari Enzo 2003 2 11 8,434.52
1969 Ford Falcon 2003 2 11 4,114.51
1903 Ford Model A 2003 2 11 3,004.98
Collectable Wooden Train 2003 2 11 3,333.74
1904 Buick Runabout 2003 2 11 3,094.68
18th century schooner 2003 2 11 5,072.71
1912 Ford Model T Delivery Wagon 2003 2 11 3,232.24
1940 Ford Delivery Sedan 2003 2 11 3,773.50
The Schooner Bluenose 2003 2 11 2,214.00
The Mayflower 2003 2 11 2,511.69
The USS Constitution Ship 2003 2 11 1,882.32
The Titanic 2003 2 11 3,594.24
The Queen Mary 2003 2 11 2,184.82
Pont Yacht 2003 2 11 1,119.25
1980s Black Hawk Helicopter 2003 2 17 4,825.44
P-51-D Mustang 2003 2 17 2,757.39
1999 Yamaha Speed Boat 2003 2 17 3,315.25
1941 Chevrolet Special Deluxe Cabriolet 2003 2 17 3,863.02
1928 British Royal Navy Airplane 2003 2 17 3,002.44
1900s Vintage Bi-Plane 2003 2 17 3,222.73
1937 Horch 930V Limousine 2003 2 17 1,732.59
Corsair F4U ( Bird Cage) 2003 2 17 2,798.00
1900s Vintage Tri-Plane 2003 2 17 1,846.00
1928 Ford Phaeton Deluxe 2003 2 17 2,156.54
1930 Buick Marquette Phaeton 2003 2 17 1,395.42
American Airlines: B767-300 2003 2 17 2,831.54
HMS Bounty 2003 2 17 2,552.70
America West Airlines B757-200 2003 2 17 3,390.48
ATA: B757-300 2003 2 17 3,644.80
F/A 18 Hornet 1/72 2003 2 17 3,344.00
American Airlines: MD-11S 2003 2 17 3,375.84
Boeing X-32A JSF 2003 2 17 2,097.60
1969 Harley Davidson Ultimate Chopper 2003 2 24 2,440.50
1996 Moto Guzzi 1100i 2003 2 24 4,128.54
2003 Harley-Davidson Eagle Drag Bike 2003 2 24 4,653.72
2002 Suzuki XREO 2003 2 24 2,562.00
1936 Harley Davidson El Knucklehead 2003 2 24 1,528.30
1997 BMW R 1100 S 2003 2 24 2,423.00
1960 BSA Gold Star DBD34 2003 2 24 2,778.56
1997 BMW F650 ST 2003 2 24 1,778.00
1968 Ford Mustang 2003 3 3 5,457.54
1968 Dodge Charger 2003 3 3 4,333.50
1970 Plymouth Hemi Cuda 2003 3 3 2,956.59
1969 Dodge Charger 2003 3 3 3,855.60
1948 Porsche 356-A Roadster 2003 3 3 2,574.88
1969 Dodge Super Bee 2003 3 3 1,902.42
1976 Ford Gran Torino 2003 3 3 3,836.41
1957 Vespa GS150 2003 3 3 2,272.12
1957 Corvette Convertible 2003 3 3 6,154.28
1982 Ducati 900 Monster 2003 3 3 2,254.35
1971 Alpine Renault 1600s 2003 3 3 1,800.30
1956 Porsche 356A Coupe 2003 3 3 5,280.00
1961 Chevrolet Impala 2003 3 3 2,080.10
1982 Ducati 996 R 2003 3 3 977.67
1974 Ducati 350 Mk3 Desmo 2003 3 3 2,720.56
2002 Yamaha YZR M1 2003 3 3 2,544.89
1993 Mazda RX-7 2003 3 10 3,054.48
1995 Honda Civic 2003 3 10 5,243.24
1999 Indy 500 Monte Carlo SS 2003 3 10 3,294.72
1992 Ferrari 360 Spider red 2003 3 10 7,400.02
1948 Porsche Type 356 Roadster 2003 3 10 5,909.78
1982 Lamborghini Diablo 2003 3 10 930.90
1965 Aston Martin DB5 2003 3 18 4,374.14
1917 Grand Touring Sedan 2003 3 18 6,426.00
1911 Ford Town Car 2003 3 18 1,646.72
1932 Model A Ford J-Coupe 2003 3 18 3,817.77
1928 Mercedes-Benz SSK 2003 3 18 5,074.39
1932 Alfa Romeo 8C2300 Spider Sport 2003 3 18 2,293.48
1957 Ford Thunderbird 2003 3 18 2,604.00
1970 Chevy Chevelle SS 454 2003 3 18 2,592.72
1966 Shelby Cobra 427 S/C 2003 3 18 1,254.83
1939 Chevrolet Deluxe Coupe 2003 3 18 577.60
1938 Cadillac V-16 Presidential Limousine 2003 3 18 1,590.03
1949 Jaguar XK 120 2003 3 18 3,555.67
1952 Citroen-15CV 2003 3 18 5,186.04
1969 Chevrolet Camaro Z28 2003 3 18 2,172.69
2002 Chevy Corvette 2003 3 18 3,565.69
1936 Mercedes Benz 500k Roadster 2003 3 18 1,693.92
1937 Lincoln Berline 2003 3 25 2,881.89
1936 Mercedes-Benz 500K Special Roadster 2003 3 25 2,328.96
1934 Ford V8 Coupe 2003 3 25 1,486.52
18th Century Vintage Horse Carriage 2003 3 25 4,052.75
1917 Maxwell Touring Car 2003 3 25 3,559.52
1936 Chrysler Airflow 2003 3 25 2,228.20
1952 Alpine Renault 1300 2003 3 24 5,717.64
1913 Ford Model T Speedster 2003 3 24 1,957.30
1958 Setra Bus 2003 3 26 2,554.44
1940 Ford Pickup Truck 2003 3 26 4,973.50
1939 Cadillac Limousine 2003 3 26 2,163.50
1996 Peterbilt 379 Stake Bed with Outrigger 2003 3 26 1,352.86
1962 LanciaA Delta 16V 2003 4 1 3,984.43
1964 Mercedes Tour Bus 2003 4 1 4,164.42
1926 Ford Fire Engine 2003 4 1 2,406.60
1992 Ferrari 360 Spider red 2003 4 1 8,128.32
1940s Ford truck 2003 4 1 4,318.94
1962 Volkswagen Microbus 2003 4 1 2,146.83
1958 Chevy Corvette Limited Edition 2003 4 1 687.36
1980’s GM Manhattan Express 2003 4 1 2,835.52
1954 Greyhound Scenicruiser 2003 4 1 1,227.24
1982 Camaro Z28 2003 4 1 3,483.48
1957 Chevy Pickup 2003 4 4 5,123.94
1998 Chrysler Plymouth Prowler 2003 4 4 6,477.26
1970 Dodge Coronet 2003 4 4 2,662.08
1992 Porsche Cayenne Turbo Silver 2003 4 4 4,683.80
Diamond T620 Semi-Skirted Tanker 2003 4 4 2,718.90
1950's Chicago Surface Lines Streetcar 2003 4 11 1,627.56
2001 Ferrari Enzo 2003 4 16 6,445.89
1969 Corvair Monza 2003 4 16 6,366.58
1969 Ford Falcon 2003 4 16 6,747.78
1903 Ford Model A 2003 4 16 3,160.81
Collectable Wooden Train 2003 4 16 1,715.28
1970 Triumph Spitfire 2003 4 16 2,685.75
1904 Buick Runabout 2003 4 16 1,695.79
18th century schooner 2003 4 16 4,887.20
1962 City of Detroit Streetcar 2003 4 16 1,168.64
The Mayflower 2003 4 16 2,863.29
The Queen Mary 2003 4 16 4,022.10
Pont Yacht 2003 4 16 2,621.00
The Titanic 2003 4 21 3,101.40
1972 Alfa Romeo GTA 2003 4 28 5,192.48
1980s Black Hawk Helicopter 2003 4 28 6,509.34
1999 Yamaha Speed Boat 2003 4 28 1,571.64
1941 Chevrolet Special Deluxe Cabriolet 2003 4 28 2,572.56
1900s Vintage Bi-Plane 2003 4 28 2,640.40
1912 Ford Model T Delivery Wagon 2003 4 28 2,540.29
1937 Horch 930V Limousine 2003 4 28 1,262.39
1940 Ford Delivery Sedan 2003 4 28 2,876.30
Corsair F4U ( Bird Cage) 2003 4 28 1,738.80
The Schooner Bluenose 2003 4 28 1,433.50
HMS Bounty 2003 4 28 2,152.67
The USS Constitution Ship 2003 4 28 2,554.36
American Airlines: MD-11S 2003 4 28 1,655.42
Boeing X-32A JSF 2003 4 28 1,126.15
1996 Moto Guzzi 1100i 2003 4 29 3,449.25
2003 Harley-Davidson Eagle Drag Bike 2003 4 29 7,304.80
P-51-D Mustang 2003 4 29 2,400.91
1936 Harley Davidson El Knucklehead 2003 4 29 2,646.84
1997 BMW R 1100 S 2003 4 29 3,865.75
1928 British Royal Navy Airplane 2003 4 29 3,627.39
1960 BSA Gold Star DBD34 2003 4 29 2,460.24
1900s Vintage Tri-Plane 2003 4 29 2,080.17
1997 BMW F650 ST 2003 4 29 2,087.80
1928 Ford Phaeton Deluxe 2003 4 29 1,994.91
1930 Buick Marquette Phaeton 2003 4 29 2,031.54
American Airlines: B767-300 2003 4 29 4,292.98
America West Airlines B757-200 2003 4 29 1,962.48
ATA: B757-300 2003 4 29 2,562.96
F/A 18 Hornet 1/72 2003 4 29 3,096.00
1969 Harley Davidson Ultimate Chopper 2003 5 7 2,928.42
2002 Suzuki XREO 2003 5 7 6,326.00
1982 Ducati 900 Monster 2003 5 7 1,861.76
1974 Ducati 350 Mk3 Desmo 2003 5 7 2,398.25
2002 Yamaha YZR M1 2003 5 7 3,186.04
1968 Ford Mustang 2003 5 8 6,537.72
1968 Dodge Charger 2003 5 8 4,215.04
1970 Plymouth Hemi Cuda 2003 5 8 2,094.08
1969 Dodge Charger 2003 5 8 2,096.00
1993 Mazda RX-7 2003 5 8 3,898.10
1948 Porsche 356-A Roadster 2003 5 8 2,681.91
1995 Honda Civic 2003 5 8 3,527.79
1992 Ferrari 360 Spider red 2003 5 8 3,429.24
1969 Dodge Super Bee 2003 5 8 1,452.15
1976 Ford Gran Torino 2003 5 8 2,808.96
1957 Vespa GS150 2003 5 8 2,067.10
1957 Corvette Convertible 2003 5 8 4,082.96
1982 Lamborghini Diablo 2003 5 8 1,354.86
1971 Alpine Renault 1600s 2003 5 8 1,727.88
1956 Porsche 356A Coupe 2003 5 8 5,857.46

This example demonstrates how to export table with complex headers to an excel file.

<div>
    <?php
    \koolreport\Excel\Table::create(array(
        ...
        "columns"=>array(
            "productName",
            "orderYear" => ["label" => "Date-Year"],
            "orderMonth" => ["label" => "Date-Month"],
            "orderDay" => ["label" => "Date-Day"],
            "dollar_sales"=>array(
                "type"=>"number",
                "decimals" => 2,
            )
        ),
        "complexHeaderLabels" => true,        
    ));
    ?>
</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')
        ->pipe(new Limit(array(
            200, 0
        )))
        ->pipe($this->dataStore('orders'));

    }
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\datagrid\DataTables;
?>
<div class="report-content">
	<div style='text-align: center;margin-bottom:30px;'>
        <h1>Excel Table Complex Header</h1>
        <p class="lead">Exporting table with complex headers</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>
			<?php
			DataTables::create(array(
				"dataSource" => $this->dataStore('orders'),
				"columns"=>array(
					"productName",
					"orderYear" => ["label" => "Date-Year"],
					"orderMonth" => ["label" => "Date-Month"],
					"orderDay" => ["label" => "Date-Day"],
					"dollar_sales"=>array(
						"type"=>"number",
						"decimals" => 2,
					)
				),
				"complexHeaderLabels" => true,
				"options" => [
					"paging" => true,
					"order" => [[4, 'desc']],
					"columnDefs" => [
						[
							"targets" => [4],
							"type" => "num-fmt",
						]
					]
				]
			));
			?>
		</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">

<div sheet-name="<?php echo $sheet1; ?>">
    <div>Orders Table</div>

    <div>
        <?php
        \koolreport\excel\Table::create(array(
            "dataSource" => $this->dataStore('orders'),
            "columns"=>array(
                "productName",
                "orderYear" => ["label" => "Date-Year"],
                "orderMonth" => ["label" => "Date-Month"],
                "orderDay" => ["label" => "Date-Day"],
                "dollar_sales"=>array(
                    "type"=>"number",
                    "decimals" => 2,
                )
            ),
            "complexHeaderLabels" => true,
            "sorting" => [
                "dollar_sales" => "desc",
            ]
        ));
        ?>
    </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");
}
customerNameproductNameproductLineorderDateorderDayorderMonthorderYearorderQuarterdollar_sales
Vitachrome Inc. 1937 Lincoln Berline Vintage Cars 2003-01-10 00:00:00 10 1 2003 1 3726.45
Vitachrome Inc. 1936 Mercedes-Benz 500K Special Roadster Vintage Cars 2003-01-10 00:00:00 10 1 2003 1 1768.33
Baane Mini Imports 1952 Alpine Renault 1300 Classic Cars 2003-01-29 00:00:00 29 1 2003 1 5571.8
Baane Mini Imports 1962 LanciaA Delta 16V Classic Cars 2003-01-29 00:00:00 29 1 2003 1 5026.14
Baane Mini Imports 1958 Setra Bus Trucks and Buses 2003-01-29 00:00:00 29 1 2003 1 3284.28
Baane Mini Imports 1940 Ford Pickup Truck Trucks and Buses 2003-01-29 00:00:00 29 1 2003 1 3307.5
Baane Mini Imports 1926 Ford Fire Engine Trucks and Buses 2003-01-29 00:00:00 29 1 2003 1 1283.48
Baane Mini Imports 1913 Ford Model T Speedster Vintage Cars 2003-01-29 00:00:00 29 1 2003 1 2489.13
Baane Mini Imports 1934 Ford V8 Coupe Vintage Cars 2003-01-29 00:00:00 29 1 2003 1 2164.4
Baane Mini Imports 18th Century Vintage Horse Carriage Vintage Cars 2003-01-29 00:00:00 29 1 2003 1 2173

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