2012-10-19 2 views
0

다른 PHP 파일을 다른 줄로 쓰고 싶습니다. 나는 그것을 할 수있는 많은 방법이 있다는 것을 압니다.다른 배열을 가지고있는 PHP에서 Excel 파일을 다운로드하십시오.

엑셀 파일을 다운로드하지만 콘텐츠에 삽입 할 수 있도록 내 배열을 지원하지 않는 작은 스크립트가 있습니다. 변경 사항이 필요한 경우 도와주세요.

감사

$shop['id']=$column['id']; 
    $shop['name']=$column['name']; 
    $shop['cat1'] = $cat1; 
    $shop['cat2'] = $cat2; 
    $shop['cat3'] = $cat3; 
    $all_shops[$column['id']] = $shop; 



$filename ="cat.xls"; 
$contents = "$shop['cat2']"; 
header('Content-type: application/ms-excel'); 
header('Content-Disposition: attachment; filename='.$filename); 
echo $contents; 

답변

-1

가장 쉬운 방법은 출력 HTML과 같은 일 콘텐츠를 스트리밍하는 것입니다. (예 : 확장명 .html을 .xls로 변경하면 Excel에서 원활하게 열립니다.)

$shop['id']=$column['id']; 
$shop['name']=$column['name']; 
$shop['cat1'] = $cat1; 
$shop['cat2'] = $cat2; 
$shop['cat3'] = $cat3; 
$all_shops[$column['id']] = $shop; 

$content = "<table>"; 
foreach($all_shops as $k => $shop){ 
    $content .= "<tr><td>ID</td><td>{$shop['id']}</td></tr>"; // add other columns 
} 
$content .= "</table>"; 

$filename ="cat.xls"; 
$contents = "$shop['cat2']"; 
header('Content-type: application/ms-excel'); 
header('Content-Disposition: attachment; filename='.$filename); 
echo $contents; 
+0

부드럽게? 가장 최근 버전의 Excel에서는 파일 형식이 파일 확장명과 일치하지 않는다는 경고를 표시합니다. 이는 "부드러운"파일 형식의 정의에 따라 달라집니다. –

관련 문제