php파일을 엑셀로 다운시 질문 있습니다.
본문
엑셀로 다운로드는 잘 되는데요 추가적으로 해야하는데 어디를 손봐야할지 전혀 감을 못잡아 이렇게 여쭈어
봅니다. 게시판 목록에서 아래처럼 시작과 종료일자를 조회한 내용만 엑셀로 다운로드 가능할까요??
그리고, 시작일자, 종료일자에 날짜를 2017-06-01로 입력해야 일자별 조회가 되던데 이를 170601 이런식으로 입력해도 조회하려 하는데 초보라 정말 어렵네요..ㅠㅠ 도와주시면 감사하겠습니다.
<input type="text" id="fr_date" name="fr_date" value="<?php echo $fr_date; ?>" class="frm_input" maxlength="10" placeholder="시작일자" > ~
<input type="text" id="to_date" name="to_date" value="<?php echo $to_date; ?>" class="frm_input" maxlength="10" placeholder="종료일자" >
~~생략
<script>
function set_date(today)
{
<?php
$date_term = date('w', G5_SERVER_TIME);
$week_term = $date_term + 7;
$last_term = strtotime(date('Y-m-01', G5_SERVER_TIME));
?>
if (today == "오늘") {
document.getElementById("fr_date").value = "<?php echo G5_TIME_YMD; ?>";
document.getElementById("to_date").value = "<?php echo G5_TIME_YMD; ?>";
} else if (today == "어제") {
document.getElementById("fr_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME - 86400); ?>";
document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME - 86400); ?>";
} else if (today == "이번주") {
document.getElementById("fr_date").value = "<?php echo date('Y-m-d', strtotime('-'.$date_term.' days', G5_SERVER_TIME)); ?>";
document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME); ?>";
} else if (today == "이번달") {
document.getElementById("fr_date").value = "<?php echo date('Y-m-01', G5_SERVER_TIME); ?>";
document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME); ?>";
} else if (today == "지난주") {
document.getElementById("fr_date").value = "<?php echo date('Y-m-d', strtotime('-'.$week_term.' days', G5_SERVER_TIME)); ?>";
document.getElementById("to_date").value = "<?php echo date('Y-m-d', strtotime('-'.($week_term - 6).' days', G5_SERVER_TIME)); ?>";
} else if (today == "지난달") {
document.getElementById("fr_date").value = "<?php echo date('Y-m-01', strtotime('-1 Month', $last_term)); ?>";
document.getElementById("to_date").value = "<?php echo date('Y-m-t', strtotime('-1 Month', $last_term)); ?>";
} else if (today == "전체") {
document.getElementById("fr_date").value = "";
document.getElementById("to_date").value = "";
window.location.href = '<?php echo G5_BBS_URL?>/board.php?bo_table=<?php echo $bo_table?>&sca=<?php echo $sca?>';
}
}
</script>
#########아래는 엑셀 다운로드 클릭시 적용되는 소스 ########
<?php
include_once('./_common.php');
$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/
=================================================================================*/
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] == "<p></p>" ) { $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 "<script>alert('출력할 내역이 없습니다.'); window.close();</script>";
exit;
}
?>
답변 1
정확히 뭘 하시력 하는지 모르겠습니다.
2017-06-01로 입력해야 일자별 조회가 되던데 이를 170601로 검색
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]}')";
}
의 하단에 추가
<?php
# 글자 수 저장
$dateLength = array (
'fr_date' => strlen($_GET['fr_date']),
'to_date' => strlen($_GET['to_date']),
);
# 시작 일자 설정
switch ($dateLength['fr_date']) {
case 6 : # 170601
$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);
break;
case 8 : # 20170601
$date['fr_date'] = substr($_GET['fr_date'], 0, 4).'-'.substr($_GET['fr_date'], 4, 2).'-'.substr($_GET['fr_date'], 6, 2);
break;
default :# 2017-06-01
$date['fr_date'] = $_GET['fr_date'];
break;
}
# 종료 일자 설정
switch ($dateLength['to_date']) {
case 6 : # 170631
$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);
break;
case 8 : # 20170631
$date['to_date'] = substr($_GET['to_date'], 0, 4).'-'.substr($_GET['to_date'], 4, 2).'-'.substr($_GET['to_date'], 6, 2);
break;
default : # 2017-06-31
$date['to_date'] = $_GET['to_date'];
break;
}
# 하단의 $_GET[fr_date] 및 $_GET[to_date] 전부 치환
# $date['fr_date'] $date['to_date']
?>
확인완료입니다 : )