게시물 내용 엑셀파일로 내보내기 문의드립니다.

게시물 내용 엑셀파일로 내보내기 문의드립니다.

QA

게시물 내용 엑셀파일로 내보내기 문의드립니다.

답변 2

본문

이번에 xe에서 그누보드로 옮겨온 초보입니다.

기존에 xe게시판 게시글(확장변수 포함)내용을 엑셀로 내보내기 기능을 사용했습니다.

소스를 조금만 수정하면.. 그누보드에서도 적용 가능할 거 같은데..

db정보와 게시판정보만 수정해서는 안되네요;;

고수님의 도움을 받을 수 있을까요??

항목에 들어갈 내용은 예시로 아무 문구나 넣어주셔도 감사하겠습니다^^

 

내보내기 엑셀파일을 생성하는 코드는 맨 하단에 있습니다.^^

 


<?php
//url 로 직접 불러오는것을 방지
if(!strstr($_SERVER['HTTP_REFERER'],$_SERVER['SERVER_NAME'])&& !strstr($_SERVER['HTTP_REFERER'],'out_excel.php')) exit;
 
$info = array(
"host" => "localhost",
"user" => "",
"pass" => "",
"db" => "",
"table" => "",
"module_srl" => "",
);
$getFields = array("regdate"); //출력원하는 칼럼을 배열로 입력
 
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=(".date('Y-m-d').") 예약현황.xls");
 
$con = mysql_connect($info[host], $info[user], $info[pass]) || die(mysql_error());
mysql_query("set names utf8");
$con_db = mysql_select_db($info[db]) || die(mysql_error());
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=Content-Type content=text/html; charset="utf-8">
</head>
<body>
<table border=1>
<tr align=center>
 
<?php
//제목 불러오기
$fields = mysql_list_fields("$info[db]", "$info[table]");
$columns = mysql_num_fields($fields);
 
for( $i=0 ; $i<$columns ; $i++ )
{
    $field[$i]=mysql_field_name($fields, $i);
    if( in_array($field[$i], $getFields) ) echo "<th>".$field[$i]."</th>";
}
 
//확장변수의 타이틀은 값이므로        
$result = mysql_query("select  var_name from xe_document_extra_keys where module_srl = $info[module_srl]");                   
while( $data = mysql_fetch_array($result) )
{                           
    echo "<th>".htmlspecialchars($data[var_name])."</th>";
}   
 
echo"</tr>";              
 
 
//데이터 불러오기
$result = mysql_query("select * from $info[table] where module_srl = $info[module_srl]");
while( $data = mysql_fetch_assoc($result) )
{
    echo"<tr>";
    foreach( $data as $key => $val )
    {
        if( in_array($key, $getFields) ) 
        {
            if ($key ==  'regdate') {  
                echo "<td   style='mso-number-format:\"0_ \";' >".htmlspecialchars($val)."</td>";                
            }elseif ($key ==  'content'){       //내용 출력할경우 태그가 그대로 출력됨          
                //echo "<td>".$val."</td>";     //셀이 두칸이상으로 늘어남
                echo "<td >".htmlspecialchars(strip_tags(str_replace(" ","",$val)))."</td>"; 
            }else {
                echo "<td>".htmlspecialchars($val)."</td>";
            }   
        }
 
        if ($key ==  'document_srl'){           //확장변수 불러올때 사용
            $d_srl=$val;
        }
 
    }
                //확장변수 출력 ////////////////////////////////////////////
                //eid리스트를 불러온다
                $query=mysql_query("select eid from xe_document_extra_keys where module_srl = $info[module_srl]");       
                while($extra_title=mysql_fetch_array($query))
                {       
                    echo"<td>";
 
                    $egetFields = array("value","eid");   
                    //확장변수 값을 불러와 eid값이 같은곳에 출력
                    $extra_result = mysql_query("select * from xe_document_extra_vars where document_srl = $d_srl");  
                    while( $edata = mysql_fetch_assoc($extra_result) )
                    {
                        $extra_str="";
                        foreach( $edata as $key => $val ){ 
                            if( in_array($key, $egetFields) ){                           
                                $extra_str = $val.",".$extra_str;
                            }
                        }
 
                        $extra_arr=explode(",",$extra_str);                                 
                        if ($extra_title[eid]==$extra_arr[0]){
 
                            //전화번호값은 "|@|" 를 "-" 로 변경
                            if($extra_title[eid]=="phone"){
                                echo str_replace("|@|","-",htmlspecialchars($extra_arr[1]));
 
                            //기타 배열값들은 ',' 로 변경
                            }elseif($extra_title[eid]=="notic"||$extra_title[eid]=="mb_cs"){
                                echo str_replace("|@|", ",",htmlspecialchars($extra_arr[1]));
                            }else{
                                echo htmlspecialchars($extra_arr[1]);                      
                            }
                        }
                    }
 
                    echo"</td>";   //eid값이 없으면 빈칸입력
                }               
                /////////////////////////////////////////////////////////////////////
 
    echo"</tr>";
}
 
 
?>
</table>
</body>
</html>

 

 

 

* 엑셀파일 내보내기 실행 파일 *


    <meta name="viewport" content="width=device-width, initial-scale=1">
    <a cond="$grant->manager" class="btn" href="out_excel.php" title="엑셀 출력"> 예약현황 엑셀출력</a>

이 질문에 댓글 쓰기 :

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 7
© SIRSOFT
현재 페이지 제일 처음으로