Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not handle int/double value on export #19

Closed
andhikaribrahim opened this issue Apr 30, 2018 · 4 comments
Closed

Could not handle int/double value on export #19

andhikaribrahim opened this issue Apr 30, 2018 · 4 comments
Labels
bug Something isn't working

Comments

@andhikaribrahim
Copy link

andhikaribrahim commented Apr 30, 2018

Cannot export the #ref id (int) & correct_value (double)

Here's my code:

    $user = Auth::user();

    if (!empty($user->province_id) && $user->type == 2) {
        $data = DB::table('student')
        	->join('student_assesment', 'student_assesment.student_id', '=', 'student.id')
        	->select(
        		'student.id',
        		'student.code',
        		'student.first_name',
        		'student.last_name',
        		'student.phone',
        		'student_assesment.correct_value as correct_value'
        	)
            ->where('student.state', '!=', 4)
            ->where('student.province_id', $user->province_id)
            ->get();
    } elseif (!empty($user->district_id) && ($user->type == 3 || $user->type == 4)) {
        $data = DB::table('student')
        	->join('student_assesment', 'student_assesment.student_id', '=', 'student.id')
        	->select(
        		'student.id',
        		'student.code',
        		'student.first_name',
        		'student.last_name',
        		'student.phone',
        		'student_assesment.correct_value as correct_value'
        	)
            ->where('student.state', '!=', 4)
            ->where('student.district_id', $user->district_id)
            ->get();
    } else {
        $data = DB::table('student')
        	->join('student_assesment', 'student_assesment.student_id', '=', 'student.id')
        	->select(
        		'student.id',
        		'student.code',
        		'student.first_name',
        		'student.last_name',
        		'student.phone',
        		'student_assesment.correct_value as correct_value'
        	)
            ->where('student.state', '!=', 4)
            ->get();
    }

    $mappingData = $data->map(function($student) {
        return [
            "#Ref Id" => strval($student->id),
            "Kode" => $student->code,
            "Name" => $student->first_name . " " . $student->last_name,
            "Phone Number" => $student->phone,
            "Correct Answer" => strval($student->correct_value),
        ];
    });

    $export = (new FastExcel($mappingData))->download('export_result.xlsx');

    return $export;
}

But when i set id & correct_value with strval() function, the data is exported.

any idea?

@rap2hpoutre
Copy link
Owner

Ok thank you for your contribution! This bug has to be fixed, I will try to tackle this issue soon.

@rap2hpoutre rap2hpoutre added the bug Something isn't working label Apr 30, 2018
@andhikaribrahim
Copy link
Author

Glad to help! Also, is there any efficient way to export like 50-100k rows of data? In my case, i tried like chunking the query result with the Query Builder chunk(n) method. But it doesn't do much.

@rap2hpoutre
Copy link
Owner

@andhikaribrahim Could you open another issue for this need? Currently, this package does not allow data chunk, but it may be considered. Thanks again!

@rap2hpoutre
Copy link
Owner

Fixed via 1f4112c. Available in v0.3.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants