ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 그누보드 PHPEXCEL 사용법
    그누보드 2020. 5. 6. 18:54
    /lib/PHPExcel 폴더 복사 붙여넣기
    
    /bbs/comment_down.php(임시 파일명)
    
    <?php
    include_once('./_common.php');
    function column_char($i) { return chr( 65 + $i ); }
    include_once(G5_LIB_PATH.'/PHPExcel.php');
    $bo_table = $_GET["bo_table"];
    $wr_id = $_GET["wr_id"];
    $headers = array('이름', 'ID', '작성일시','댓글');
    $widths  = array(20, 20, 20, 40);
    $header_bgcolor = 'FFABCDEF';
    $last_char = column_char(count($headers) - 1);
    $sql = " select * from g5_write_{$bo_table} where wr_parent = '$wr_id' and wr_is_comment = 1 order by wr_comment, wr_comment_reply ";
    $result = sql_query($sql);
    for($i=1; $row=sql_fetch_array($result); $i++) {
        $rows[] =
        array($row['wr_name'],
            $row['mb_id'],
            $row['wr_datetime'],
            $row['wr_content']);
    }
    $data = array_merge(array($headers), $rows);
    $excel = new PHPExcel();
    $excel->setActiveSheetIndex(0)->getStyle( "A1:${last_char}1" )->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($header_bgcolor);
    $excel->setActiveSheetIndex(0)->getStyle( "A:$last_char" )->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER)->setWrapText(true);
    foreach($widths as $i => $w) $excel->setActiveSheetIndex(0)->getColumnDimension( column_char($i) )->setWidth($w);
    $excel->getActiveSheet()->fromArray($data,NULL,'A1');
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"commentlist-".date("ymd", time()).".xls\"");
    header("Cache-Control: max-age=0");
    $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
    $writer->save('php://output');
    ?>

    댓글

Designed by Tistory.