KoolReport's Forum

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

Excel document was corrupted on export #154

Open dimasmaliq opened this topic on on Nov 22, 2017 - 8 comments

dimasmaliq commented on Nov 22, 2017

Hi guys, i've faced the problem while exporting pivot table with so many columns into excel document.

here is my export.php code:

<?php
require_once "ppg.php";
$report = new ppg;

if ($_POST['laporan'] == "1") {
	$report->run()->exportToExcel(array(
		"dataStores"=>array(
			'status_ajuan'=>array(
				'rowDimension'=>'row',
				'columnDimension'=>'column',
				'measures'=>array(
                    'jml - sum',
				),
				'headerMap'=>array(
                    'jml - sum'=>'Propinsi - Kota',
				),				
				'totalName'=>'Grand Total',
			)
		)
	))->toBrowser('Laporan PPG Berdasarkan Status Ajuan.xls');
}

else if ($_POST['laporan'] == "2") {
	$report->run()->exportToExcel(array(
		"dataStores"=>array(
			'status_aktivasi'=>array(
				'rowDimension'=>'row',
				'columnDimension'=>'column',
				'measures'=>array(
                    'jml - sum',
				),
				'headerMap'=>array(
                    'jml - sum'=>'Propinsi - Kota',
				),				
				'totalName'=>'Grand Total',
			)
		)
	))->toBrowser('Laporan PPG Berdasarkan Status Aktivasi.xls');
}

else {
	$report->run()->exportToExcel(array(
		"dataStores"=>array(
			'prodi'=>array(
				'rowDimension'=>'row',
				'columnDimension'=>'column',
				'measures'=>array(
                    'jml - sum',
				),
				'headerMap'=>array(
                    'jml - sum'=>'Propinsi - Kota',
				),				
				'totalName'=>'Grand Total',
			)
		)
	))->toBrowser('Laporan PPG Berdasarkan Program Studi.xls');
}

for first and 2nd report, there is no problem:

but not for 3rd report, here is the error message while i open these document on excel:

all of data was lost

David Winterburn commented on Nov 23, 2017

Hi there,

Could you please render the third datastore using the PivotTable widget and let us know the result? Thanks!

dimasmaliq commented on Nov 23, 2017

here is:

David Winterburn commented on Nov 24, 2017

Hi there,

Would you please send us a sample of your data for the third datastore as well as your php code? We'd like to replicate this problem to debug it. Thanks!

dimasmaliq commented on Nov 24, 2017

here is the sample of data:

propinsi,kota,prodi,jml
Aceh,Kab. Aceh Barat,Bahasa Indonesia,6
Aceh,Kab. Aceh Barat,Bimbingan dan Konseling,16
Aceh,Kab. Aceh Barat,Biologi,15
Aceh,Kab. Aceh Barat,Budidaya Perairan,1
Aceh,Kab. Aceh Barat,Ekonomi,5
Aceh,Kab. Aceh Barat,Fisika,4
Aceh,Kab. Aceh Barat,Geografi,6
Aceh,Kab. Aceh Barat,Ilmu keolahragaan dan kepelatihan ,1
Aceh,Kab. Aceh Barat,Kimia,5
Aceh,Kab. Aceh Barat,Manajemen,2
Aceh,Kab. Aceh Barat,Matematika,13
Aceh,Kab. Aceh Barat,Pemasaran/Ekonomi,1
Aceh,Kab. Aceh Barat,Pendidikan Antropologi,1
Aceh,Kab. Aceh Barat,Pendidikan Bahasa dan/atau Sastra Arab,3
Aceh,Kab. Aceh Barat,Pendidikan Bahasa dan/atau Sastra Indonesia,14
Aceh,Kab. Aceh Barat,Pendidikan Bahasa dan/atau Sastra Inggris,35
Aceh,Kab. Aceh Barat,Pendidikan Bahasa dan/atau Sastra Perancis,1
Aceh,Kab. Aceh Barat,Pendidikan Bahasa Indonesia,2
Aceh,Kab. Aceh Barat,Pendidikan Biologi,21
Aceh,Kab. Aceh Barat,Pendidikan Ekonomi,9
Aceh,Kab. Aceh Barat,Pendidikan Ekonomi Koperasi,3
Aceh,Kab. Aceh Barat,Pendidikan Fisika,12
Aceh,Kab. Aceh Barat,Pendidikan Geografi,8
Aceh,Kab. Aceh Barat,Pendidikan IPA,1
Aceh,Kab. Aceh Barat,Pendidikan Jasmani, Kesehatan, dan Rekreasi,13
Aceh,Kab. Aceh Barat,Pendidikan jasmani, olah raga dan kesehatan ,8
Aceh,Kab. Aceh Barat,Pendidikan Kepelatihan Olah Raga,2
Aceh,Kab. Aceh Barat,Pendidikan Kimia,15
Aceh,Kab. Aceh Barat,Pendidikan Matematika,27
Aceh,Kab. Aceh Barat,Pendidikan Pancasila dan Kewarganegaraan,12
Aceh,Kab. Aceh Barat,Pendidikan Sejarah,16
Aceh,Kab. Aceh Barat,Perikanan dan Ilmu Kelautan,1
Aceh,Kab. Aceh Barat,PGPAUD,3
Aceh,Kab. Aceh Barat,PGSD,201
Aceh,Kab. Aceh Barat,Sastra Inggris,1
Aceh,Kab. Aceh Barat,Sejarah,1
Aceh,Kab. Aceh Barat,Seni Kriya,1
Aceh,Kab. Aceh Barat,Seni Musik,1
Aceh,Kab. Aceh Barat,Seni Tari,3
Aceh,Kab. Aceh Barat,Sosiologi,1
Aceh,Kab. Aceh Barat,Tadris Bahasa Inggris,1
Aceh,Kab. Aceh Barat,Teknik Mesin,1
Aceh,Kab. Aceh Barat Daya,Agribisnis Pertanian,1
Aceh,Kab. Aceh Barat Daya,Agronom,1
Aceh,Kab. Aceh Barat Daya,Bahasa Indonesia,8
Aceh,Kab. Aceh Barat Daya,Bimbingan dan Konseling,10
Aceh,Kab. Aceh Barat Daya,Biologi,14
Aceh,Kab. Aceh Barat Daya,Dunia Usaha,1
Aceh,Kab. Aceh Barat Daya,Ekonomi,1
Aceh,Kab. Aceh Barat Daya,Ekonomi Koperasi,2
David Winterburn commented on Nov 24, 2017

Hi,

Would you please post your report's php code as well? Thanks!

dimasmaliq commented on Nov 24, 2017

ppg.php

.
.
$this->src('gpo')
        ->query("
            SELECT 
            CASE WHEN a.sekolah_id<>0 THEN m2.keterangan ELSE m21.keterangan END propinsi,
            CASE WHEN a.sekolah_id<>0 THEN m5.keterangan ELSE m51.keterangan END kota,
            m3.keterangan prodi,
            COUNT(DISTINCT a.ptk_id) jml
            FROM gpodb.ptk a 
            INNER JOIN gpodb.ajuan_ptk_ppg c ON a.ptk_id=c.ptk_id
            LEFT JOIN gpodb.sekolah d ON a.sekolah_id=d.sekolah_id

            LEFT JOIN gpodb.m_jurusan_ppg m3 ON c.k_jurusan_ppg=m3.k_jurusan_ppg

            LEFT JOIN gpodb.m_propinsi m2 ON d.k_propinsi=m2.k_propinsi
            LEFT JOIN gpodb.m_kota m5 ON d.k_kota=m5.k_kota
            LEFT JOIN gpodb.m_propinsi m21 ON a.k_propinsi=m21.k_propinsi
            LEFT JOIN gpodb.m_kota m51 ON a.k_kota=m51.k_kota

            WHERE c.k_ajuan_ppg IN (2,3)

            GROUP BY propinsi, kota, prodi;
        ")        
        ->saveTo($prodi);

        $prodi
        ->pipe(new Group(array(
            "by"=>"prodi",
            "sum"=>"jml"
        )))
        ->pipe(new Sort(array(
            "jml"=>"desc",
        )))
        ->pipe(new Limit(array(
            5
        )))
        ->pipe($this->dataStore("proditotal"));

        $prodi
        ->pipe(new Pivot(array(
            'dimensions'=>array(
                'column'=>'prodi',
                'row'=>'propinsi, kota',
            ),
            'aggregates'=>array(
                'sum'=>'jml',
            )
        )))
        ->pipe($this->dataStore("prodi"));

ppg.view.php :

.
.
$dataStore = $this->dataStore('prodi');
PivotTable::create(array(
	"dataStore"=>$dataStore,
	'rowDimension'=>'row',
	'columnDimension'=>'column',
	'measures'=>array(
        'jml - sum',
	),				
	'headerMap'=>array(    
        'jml - sum'=>'Propinsi',
	),
	'rowCollapseLevels'=>array(0),
	//'totalName'=>'Grand Total',
	//'hideTotalRow' => true,
	'hideTotalColumn' => true,
));

BarChart::create(array(
	"dataStore"=>$this->dataStore('proditotal'),
	"width"=>"100%",
	"height"=>"100%",
	"columns"=>array(		
		"prodi"=>array(
			"label"=>"Program Studi"
		),
		"jml"=>array(
			"label"=>"Jumlah PTK"
		)        	
	),
));	
David Winterburn commented on Nov 24, 2017

Hi there,

I have tried exporting to excel with your code and sample data successfully.

So the problem might lie in other part of the data. If it's possible, please send us your whole data for the store "prodi" to our email support@koolphp.net. Please use semicolon ";" or "|" to separate because some of your fields already have comma "," in their values.

dimasmaliq commented on Nov 24, 2017

Okay, please check your email

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