상품리스트 엑셀출력
본문
상품리스트 엑셀출력을 아래와 같이 알음알음 알아가며 소스를 적용시켜서 잘 사용하고 있는데요...
엑셀출력시 등록순(날짜)? 으로 출력이 되는거 같아요..
제조사가 날짜별로 중구난방인데 출력시 등록날짜와 상관없이 제조사별로 묶어서 출력할수는 없을까요?..
<?php
include_once('./_common.php');
auth_check($auth[$sub_menu], 'r');
// MS엑셀 XLS 데이터로 다운로드 받음
$sql = " SELECT *
FROM {$g5['g5_shop_item_table']} ";
$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, "tmp-productlist.xls");
$workbook = new writeexcel_workbook($fname);
$worksheet = $workbook->addworksheet();
// Put Excel data
$data = array('상품고유번호', '제조사', '판매가격', '상품명');
$data = array_map('iconv_euckr', $data);
$col = 0;
foreach($data as $cell) {
$worksheet->write(0, $col++, $cell);
}
$save_it_id = '';
for($i=1; $row=sql_fetch_array($result); $i++)
{
$row = array_map('iconv_euckr', $row);
$worksheet->write($i, 0, ' '.$row['it_id']);
$worksheet->write($i, 1, ' '.$row['it_maker']);
$worksheet->write($i, 2, ' '.$row['it_price']);
$worksheet->write($i, 3, $row['it_name']);
}
$workbook->close();
header("Content-Type: application/x-msexcel; name=\"상품리스트-".date("ymd", time()).".xls\"");
header("Content-Disposition: inline; filename=\"상품리스트-".date("ymd", time()).".xls\"");
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);
exit;
?>
답변 1
// MS엑셀 XLS 데이터로 다운로드 받음
$sql = " SELECT *
FROM {$g5['g5_shop_item_table']} order by it_maker ASC ";