Rumah > php教程 > PHP源码 > teks badan

将数组输出为excel文件

PHP中文网
Lepaskan: 2016-05-25 17:01:49
asal
1625 orang telah melayarinya

将数组输出为excel文件

<?php
/** Error reporting */
error_reporting(E_ALL);

/** PHPExcel */
include FCPATH.&#39;vendor/Excel/excel/PHPExcel.php&#39;;
include FCPATH.&#39;vendor/Excel/excel/PHPExcel/Writer/Excel5.php&#39;;


function download(  $column , $datalist) {
// Create new PHPExcel object

$objPHPExcel = new PHPExcel();

// Set properties

$objPHPExcel->getProperties()->setCreator("Michael");
$objPHPExcel->getProperties()->setLastModifiedBy("MOT");
$objPHPExcel->getProperties()->setTitle("36lean email list");
$objPHPExcel->getProperties()->setSubject("Emails");
$objPHPExcel->getProperties()->setDescription("Array to Excel");

// Add some data
$objPHPExcel->setActiveSheetIndex(0);
$basic = &#39;A&#39;;
foreach ($column as $c) {

    $objPHPExcel->getActiveSheet()->SetCellValue( $basic.&#39;1&#39;, $c);
    
    $basic ++ ;
}

$max_length = count( $datalist) - 1;

for ($count = 0; $count <= $max_length; $count++) { 

    $basic = 65;

    var_dump( $datalist[$count]);

    foreach ($datalist[$count] as $key => $d) {

        $basic = chr( $basic);

        $objPHPExcel->getActiveSheet()->SetCellValue( $basic.($count+2) , $d);

        $basic = ord( $basic) + 1;
    }

    $basic = 65;
}


//$objPHPExcel->getActiveSheet()->SetCellValue(&#39;A1&#39;, &#39;Hello&#39;);

// Rename sheet

$objPHPExcel->getActiveSheet()->setTitle(&#39;Simple&#39;);

        
// Save Excel 2007 file
$fhandle = opendir(&#39;data/download/&#39;);

while($file = readdir( $fhandle))
{
    if( is_file( &#39;data/download/&#39;.$file))
    {
        unlink( &#39;data/download/&#39;.$file);
    }
}

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$filename = &#39;data/download/&#39;.md5(time()).&#39;.xls&#39;;
$objWriter->save($filename);

return base_url( $filename);
//header(&#39;Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&#39;);
//header(&#39;Cache-Control: max-age=0&#39;);

}
Salin selepas log masuk

 以上就是将数组输出为excel文件的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan