• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

PHP'den excel'e veri aktarırken direk ilk sutuna yazdırıyor?

balanar

Altın Üye
Katılım
22 Şubat 2021
Mesajlar
348
Excel Vers. ve Dili
Excel 2007
Altın Üyelik Bitiş Tarihi
09-03-2027
Merhaba, aşağıdaki kodla excele aktarma yapıyor. Ama her satır'ın A sutununa komple yazıyor adsoyadı sicil noyu vs..

SicilNo', 'AdSoyad', 'GorevUnvani', 'GorevMudurlugu', 'Tc', 'BaslamaTarihi', 'KadroMudurlugu
A B C D E F G şeklinde tek tek sutunlara yazdırabilmek.. Bu konu bilgisi olan var mı?


Kod:
<?php

session_start();
require_once 'config/config.php';
require_once BASE_PATH . '/includes/auth_validate.php';

$db = getDbInstance();
$select = array('SicilNo', 'AdSoyad', 'GorevUnvani', 'GorevMudurlugu', 'Tc', 'BaslamaTarihi', 'KadroMudurlugu');


$chunk_size = 100;
$offset = 0;

$data = $db->withTotalCount()->get('personeller');
$total_count = $db->totalCount;

$handle = fopen('php://memory', 'w');

fputcsv($handle,$select);
$filename = 'export_personeller.csv';


$num_queries = ($total_count/$chunk_size) + 1;

//Prevent memory leak for large number of rows by using limit and offset :
for ($i=0; $i<$num_queries; $i++){

    $rows = $db->get('personeller',Array($offset,$chunk_size), $select);
    $offset = $offset + $chunk_size;
    foreach ($rows as $row) {

        fputcsv($handle,array_values($row));
    }
}

// reset the file pointer to the start of the file
fseek($handle, 0);
// tell the browser it's going to be a csv file
header('Content-Type: application/csv; charset=UTF-8');
// Save instead of displaying csv string
header('Content-Disposition: attachment; filename="'.$filename.'";');
//Send the generated csv lines directly to browser
echo "\xEF\xBB\xBF"; // UTF-8 BOM
fpassthru($handle);
 
Üst