PHP code example of ikkez / f3-sheet

1. Go to this page and download the library: Download ikkez/f3-sheet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ikkez / f3-sheet example snippets


$excel = \Sheet::instance();

// data array
$rows = [ 
	[
		"name" => "rose",
		"color" => "red",
		"num" => 15
	],
	[
		"name" => "daisy",
		"color" => "yellow",
		"num" => 25,
	],
	[
		"name" => "orchid",
		"color" => "purple",
		"num" => 7
	]
];
// header array to rename the field labels and sort/reorder the data array 
$headers = ['name'=>'Name', 'num'=>'Number', 'color'=>'Flower Color'];

$excel->renderXLS($rows,$headers,"flowers.xls");

$rows = [ 
	[
		"rose",
		"red",
		15
	],
	[
		"daisy",
		"yellow",
		25,
	],
	[
		"orchid",
		"purple",
		7
	]
];
$rows = \Sheet::instance()->applyHeader($rows,['name','color','num']);


//Setup mapper
$items = new \DB\SQL\Mapper($db,'mytable');

//Load all items and map to associative array
$all = array_map(array($items,'cast'),$items->find());

$csv = \Sheet::instance();
$csv->renderCSV($all, $items->fields(), "items.csv");