KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Using a button to generate an Excel Download #3466

Open Wayland Games opened this topic on on Dec 3 - 1 comments

Wayland Games commented on Dec 3

Hi there,

I have a dashboard which I would like to include a button which when clicked generates an Excel spreadsheet to download. I've created a Button class:

<?php

namespace Pulse\Button;

use Carbon\Carbon;
use koolreport\dashboard\inputs\Button;
use koolreport\excel\ExcelExportable;
use Pulse\DataSource\WaylandOrderwiseDB;

class DownloadOutstandingLinesButton extends Button
{
	use ExcelExportable;

	public function onInit(): void
	{
		$this->text("Download")
			->type("primary")
			->onClick(function() {
				return WaylandOrderwiseDB::rawSQL("
				SELECT
				  vad_description,
				  oli_qty_tbsent,
				  oli_foreign_gross,
				  oli_foreign_vat,
				  oli_foreign_net,
				  os_description
				FROM 
					order_line_item
				    INNER JOIN order_header ON oli_oh_id = oh_id
				    INNER JOIN order_status ON oh_os_id = os_id
				    INNER JOIN variant_detail ON oli_vad_id = vad_id
				WHERE 
					oli_qty_tbsent > 0 
					AND oh_os_id IN(1, 4)
			")
			->run()
			->sort(['vad_description' => 'asc'])
			->exportToExcel()
			->toBrowser(sprintf("outstanding_orders_%s", Carbon::now('Europe/London')->format('Y-m-d')));
		});
	}
}

However I'm getting the following error:

Message: Call to undefined method koolreport\core\DataStore::exportToExcel()

I thought as I included the trait use ExcelExportable it would be fine?

Could someone point me in the direction of how I could do this please?

Wayland Games commented 18 hours ago

Hi, it's been a week, has anyone been able to provide some help if this is achievable?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Excel