KoolReport's Forum

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

BigSpreadsheetExportable #2749

Open James Schlies opened this topic on on Jul 4, 2022 - 1 comments

James Schlies commented on Jul 4, 2022

I'm trying to use BigSpreadsheetExportable to download a very large file (200,000 recs). However, then the dataset is large, things become very slow. Any advice ` <?php

namespace UCSF\DOM\Reports\DivisionRpt;

use koolreport\blade\Engine; use koolreport\laravel\Friendship; use UCSF\DOM\Reports\KoolReport;

class PBHBDetailDownload extends KoolReport {

use Friendship;
use Engine;
use \koolreport\excel\BigSpreadsheetExportable;
/*
 * ======================================
 * NOTE FOR COLUMNS WITH TYPE "NUM-FMT":
 * ======================================
 * using type num-fmt so that sorting is based on number not string
 * num-fmt does not accept the decimal property
 * thus using formatValue to format value by 2 decimal places
 * if need a prefix such as '$' use "$".number_format(...);
*/
/**
 * @return string[]
 */
static public function determine_columns()
{
    return [
        'trans_type',
        'period',
        'division_rpt_division_name',
        'cost_center',
        'division_rpt_dep_name',
        'cpt_code',
        'modifier_one',
        'modifier_two',
        'modifier_three',
        'modifier_four',
        'units',
        'charge',
        'payment',
        'wRVU',
        'billing_provider_display_name',
        'billingproviderID',
        'performing_provider_display_name',
        'performingproviderID',
        'service_date',
        'post_date',
        'pos_name_full',
    ];
}

/**
 * @return \array[][]
 */
function settings()
{
    return [
        "dataSources" => [
            "PBHBDetailDownload" => [
                "connectionString" => "mysql:host=" . env('DB_HOST', 'domboNext_host') . ";dbname=" . env('DB_DATABASE', 'domboNext_dbname'),
                "username"         => env('DB_USERNAME', 'domboNext_username'),
                "password"         => env('DB_PASSWORD', 'domboNext_username'),
                "charset"          => "utf8",
            ],
        ],
    ];
}

/**
 * @return void|null
 * @throws \Exception
 */
protected function setup()
{
    $this->src('PBHBDetailDownload')
         ->query($this->params['query_sql'])
         ->pipe($this->dataStore('PBHBDetailDownload'));
}

}

ReportObj->exportToCSV(

            array(
                "dataStores" => array(
                    "PBHBDetailDownload" => [
                        "separator" => ",", // default separator = "," i.e. comma
                        "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                        "typeEnclosures" => [
                            "string" => "\"", // default string enclosure is general enclosure
                            "date" => "\"", // default date enclosure is general enclosure
                            "datetime" => "\"", // default datetime enclosure is general enclosure
                            "number" => "", // default number enclosure = "" i.e. empty string
                            "boolean" => "", // default boolean enclosure = "" i.e. empty string
                        ],
                    ],
                ),

                // General options for all datastores
                "useLocalTempFolder" => true,
                "autoDeleteTempFile" => true,
                "BOM" => false, // default bom = false
                // "buffer" => 100000, // unit: KB ~ 1000 bytes. Default buffer = 1000 KB
                "buffer" => PHP_INT_MAX,
            ),
        )
               ->toBrowser("PBHBDetailDownload.csv");



Sebastian Morales commented on Jul 5, 2022

At the moment, for CSV exporting the normal CSVExportable trait is much better optimized at speed and memory than BigSpreadsheetExportable one:

class MyReport extends koolreport\KoolReport
{
    use \koolreport\excel\CSVExportable;

You can check and copy a part of our online example for huge CSV exporting:

https://www.koolreport.com/examples/reports/excel/csv_exportable/

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
None yet

None