테스트 사이트 - 개발 중인 베타 버전입니다

php파일을 엑셀로 다운시 질문 있습니다. 채택완료

wjdgjs1982 8년 전 조회 3,391

엑셀로 다운로드는 잘 되는데요 추가적으로 해야하는데 어디를 손봐야할지 전혀 감을 못잡아 이렇게 여쭈어

봅니다. 게시판 목록에서 아래처럼 시작과 종료일자를 조회한 내용만 엑셀로 다운로드 가능할까요??

그리고, 시작일자, 종료일자에 날짜를 2017-06-01로 입력해야 일자별 조회가 되던데 이를 170601 이런식으로 입력해도 조회하려 하는데 초보라 정말 어렵네요..ㅠㅠ 도와주시면 감사하겠습니다.

     ~     

~~생략

#########아래는 엑셀 다운로드 클릭시 적용되는 소스 ########

$csv = 'xls';

// MS엑셀 XLS 데이터로 다운로드 받음 if ($csv == 'xls') {    if($_GET[stx]){   $searches .= "and (wr_subject = '{$_GET[stx]}' or wr_content = '{$_GET[stx]}' or wr_1 = '{$_GET[stx]}' or wr_2 = '{$_GET[stx]}' or wr_3 = '{$_GET[stx]}'  or wr_4 = '{$_GET[stx]}'  or wr_5 = '{$_GET[stx]}'  or wr_6 = '{$_GET[stx]}'  or wr_7 = '{$_GET[stx]}'  or wr_8 = '{$_GET[stx]}'  or wr_9 = '{$_GET[stx]}'  or wr_10 = '{$_GET[stx]}'  or wr_11 = '{$_GET[stx]}'  or wr_12 = '{$_GET[stx]}'  or wr_13 = '{$_GET[stx]}'  or wr_14 = '{$_GET[stx]}'  or wr_15 = '{$_GET[stx]}'  or wr_16 = '{$_GET[stx]}'  or wr_17 = '{$_GET[stx]}'  or wr_18 = '{$_GET[stx]}'  or wr_19 = '{$_GET[stx]}'  or wr_20 = '{$_GET[stx]}')";  }    if($_GET[fr_date] && $_GET[to_date]){

  $fr_date_a = $_GET[fr_date]." 00:00:00";   $to_date_a = $_GET[to_date]." 23:59:59";

  $searches .= "and (wr_1 between '{$fr_date_a}' and '{$to_date_a}') ";  }

    $sql = " SELECT * FROM g5_write_{$bo_table} where wr_is_comment = '0' {$searches}";     $result = sql_query($sql);     $cnt = sql_num_rows($result);     if (!$cnt)         alert("출력할 내역이 없습니다.");

    /*================================================================================     php_writeexcel http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/">http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/     =================================================================================*/

    include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_workbook.inc.php');     include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_worksheet.inc.php');

    $fname = tempnam(G5_DATA_PATH, "Report.xls");     $workbook = new writeexcel_workbook($fname);     $worksheet = $workbook->addworksheet();

    // Put Excel data     $data = array('No','Date','Business NAME','Model','Adjance','Combination','Layer','Type','Unit','Running','Stroke','POINT','QTY','JIG/SET','Pin','TEST','Amount','Information','Remark');     $data = array_map('iconv_euckr', $data);

    $col = 0;     foreach($data as $cell) {         $worksheet->write(0, $col++, $cell);     }

    for($i=1; $row=sql_fetch_array($result); $i++)     {         $row = array_map('iconv_euckr', $row);      if($row[wr_36] == "." || $row[wr_36] == "

"  ) { $wr_36 = ''; } else { $wr_36 = $row[wr_36]; }   if($row[wr_content] == "." || $row[wr_content] == ""  ) { $wr_content = ''; } else { $wr_content = $row[wr_content]; }   $up_date = date("y/m/d", strtotime($row['wr_datetime']));    $worksheet->write($i, 0, $i);            $worksheet->write($i, 1, $row['wr_19']);    $worksheet->write($i, 2, $row['wr_3']);    $worksheet->write($i, 3, $row['wr_subject']);    $worksheet->write($i, 4, $row['wr_8']);               $worksheet->write($i, 5, $row['wr_13']);          $worksheet->write($i, 6, $row['wr_15']);          $worksheet->write($i, 7, $row['wr_29']);          $worksheet->write($i, 8, $row['wr_12']);          $worksheet->write($i, 9, $row['wr_17']);          $worksheet->write($i, 10, $row['wr_16']);          $worksheet->write($i, 11, $row['wr_9']);          $worksheet->write($i, 12, $row['wr_27']);    $worksheet->write($i, 13, number_format($row['wr_30']));    $worksheet->write($i, 14, $row['wr_31']);    $worksheet->write($i, 15, $row['wr_32']);    $worksheet->write($i, 16, number_format(floor($row['wr_34'])));    $worksheet->write($i, 17, strstr($wr_36));      $worksheet->write($i, 18, $wr_content);       }

    $workbook->close();    header("Content-charset=utf-8");     header("Content-Type: application/x-msexcel; name=\"Report".date("ymd", time()).".xls\"");     header("Content-Disposition: inline; filename=\"Report_".date("ymd", time()).".xls\"");     $fh=fopen($fname, "rb");     fpassthru($fh);     unlink($fname);

    exit; }

if (mysql_num_rows($result) == 0) {     echo "";     exit; } ?>  

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트

정확히 뭘 하시력 하는지 모르겠습니다.

2017-06-01로 입력해야 일자별 조회가 되던데 이를 170601로 검색 

</span></p><p>
</p><p><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 10pt;">if($_GET[stx]){ </span><br style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;"><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 10pt;">  $searches .= "and (wr_subject = '{$_GET[stx]}' or wr_content = '{$_GET[stx]}' or wr_1 = '{$_GET[stx]}' or wr_2 = '{$_GET[stx]}' or wr_3 = '{$_GET[stx]}'  or wr_4 = '{$_GET[stx]}'  or wr_5 = '{$_GET[stx]}'  or wr_6 = '{$_GET[stx]}'  or wr_7 = '{$_GET[stx]}'  or wr_8 = '{$_GET[stx]}'  or wr_9 = '{$_GET[stx]}'  or wr_10 = '{$_GET[stx]}'  or wr_11 = '{$_GET[stx]}'  or wr_12 = '{$_GET[stx]}'  or wr_13 = '{$_GET[stx]}'  or wr_14 = '{$_GET[stx]}'  or wr_15 = '{$_GET[stx]}'  or wr_16 = '{$_GET[stx]}'  or wr_17 = '{$_GET[stx]}'  or wr_18 = '{$_GET[stx]}'  or wr_19 = '{$_GET[stx]}'  or wr_20 = '{$_GET[stx]}')";</span><br style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 14.004px;"><span style="color: rgb(72, 72, 72); font-family: 돋움, Dotum, sans-serif; font-size: 10pt;"> }
</span><span style="font-size: 10pt;">의 하단에 추가</span></p><p>
</p><p><span style="font-size: 13.3333px;"><?php</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span># 글자 수 저장</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>$dateLength = array (</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>'fr_date' => strlen($_GET['fr_date']),</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>'to_date' => strlen($_GET['to_date']),</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>);</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span># 시작 일자 설정</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>switch ($dateLength['fr_date']) { </span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>case 6 : # 170601</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">			</span>$date['fr_date'] = substr(date('Y'), 0, 2).substr($_GET['fr_date'], 0, 2).'-'.substr($_GET['fr_date'], 2, 2).'-'.substr($_GET['fr_date'], 4, 2); </span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>break;</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>case 8 : # 20170601</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">			</span>$date['fr_date'] = substr($_GET['fr_date'], 0, 4).'-'.substr($_GET['fr_date'], 4, 2).'-'.substr($_GET['fr_date'], 6, 2); </span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>break;</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>default :# 2017-06-01</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">			</span>$date['fr_date'] = $_GET['fr_date'];</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>break;</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>}</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span># 종료 일자 설정</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>switch ($dateLength['to_date']) { </span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>case 6 : # 170631</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">			</span>$date['to_date'] = substr(date('Y'), 0, 2).substr($_GET['to_date'], 0, 2).'-'.substr($_GET['to_date'], 2, 2).'-'.substr($_GET['to_date'], 4, 2); </span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>break;</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>case 8 : # 20170631</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">			</span>$date['to_date'] = substr($_GET['to_date'], 0, 4).'-'.substr($_GET['to_date'], 4, 2).'-'.substr($_GET['to_date'], 6, 2); </span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>break;</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>default : # 2017-06-31</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">			</span>$date['to_date'] = $_GET['to_date'];</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">		</span>break;</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>}</span></p><p><span style="font-size: 13.3333px;">
</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span># 하단의 $_GET[fr_date] 및 $_GET[to_date] 전부 치환</span></p><p><span style="font-size: 13.3333px;"><span class="Apple-tab-span" style="white-space:pre">	</span>#         $date['fr_date']    $date['to_date']</span></p><p><span style="font-size: 13.3333px;">?></span></p><p><span style="font-size: 10pt;">

확인완료입니다 : )

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

w
wjdgjs1982
8년 전
우와~~~정말 답변 감사드립니다.^^

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인