Excel로 자료 저장할 때 저장할 시트 정하기
본문
<?php
include_once("./_common.php");
if ( ! function_exists('utf2euc')) {
function utf2euc($str) {
return iconv("UTF-8","cp949//IGNORE", $str);
}
}
if ( ! function_exists('is_ie')) {
function is_ie() {
return isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false);
}
}
$sql_common = " from {$g5['g5_shop_category_table']} ";
$sql_search = " where 1";
#echo $stx; exit;
if ($stx) {
$sql_search .= " and ( ";
switch ($sfl) {
case 'ca_name' :
$sql_search .= " ({$sfl} >= '{$stx}') ";
break;
case 'ca_id' :
$sql_search .= " ({$sfl} = '{$stx}') ";
break;
default :
$sql_search .= " ({$sfl} like '{$stx}%') ";
break;
}
$sql_search .= " ) ";
}
if (!$sst) {
$sst = "ca_id";
$sod = "asc";
}
$sql_order = " order by {$sst} {$sod} ";
$sql = " select count(*) as cnt {$sql_common} {$sql_search} {$sql_order} ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$qry = sql_query("select * {$sql_common} {$sql_search} {$sql_order}");
/*================================================================================
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.xls");
$workbook = new writeexcel_workbook($fname);
$worksheet = $workbook->addworksheet();
$num2_format =& $workbook->addformat(array(num_format => '\0#'));
// Put Excel data
$data = array(
"ca_id"=>"ID",
"ca_name"=>"NAME",
);
$data = array_map('iconv_euckr', $data);
$col = 0;
foreach($data as $cell) {
$worksheet->write(0, $col++, $cell);
}
for($i=1; $res=sql_fetch_array($qry); $i++)
{
$res = array_map('iconv_euckr', $res);
$col = 0;
foreach($data as $key=>$cell) {
$worksheet->write($i, $col++, $res[$key]);
}
}
$workbook->close();
$filename = "엑셀파일명-".date("ymd", time()).".xls";
if( is_ie() ) $filename = utf2euc($filename);
header("Content-Type: application/x-msexcel; name=".$filename);
header("Content-Disposition: inline; filename=".$filename);
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);
?>
해당 소스로 테이블의 값을 저장하는데 Sheet2에 넣을려고합니다.
Shee1에는 다른 내용이 들어가야해서요
저 코드에서 뭘 추가해야지 원하는 Sheet로 저장가능할까요?
!-->
답변을 작성하시기 전에 로그인 해주세요.