2011-08-09 5 views
2

안녕하세요 데 문제가 예를 들어 엑셀 배열에서 값을 내보내는는 어떻게 수출 것이다 다음내보내기 값

echo "<table ' border='1' >" 
    echo "<th>ComputerName</th>")); 
    echo "<th>SerialNumber</th>"; 
    echo "<th>SystemModel</th>"; 
    echo "<th>DateTime</th>"; 
    echo "<th>Software</th>"; 
    echo "<th>Hardware</th>"; 
    echo "<th>Support</th>"; 
    echo "<th>Delete</th>"; 
    echo "</tr>"; 

$alt_color = 0; 
while($row = mysql_fetch_array($result)) 

    { 
    error_reporting (E_ALL^E_NOTICE); 
    //foreach($array_values as $value) 
$bgc = ($alt_color % 2 ? 'Dark' : 'Light'); 
    echo "<tr class=".$bgc.">"; 
    //echo "<td><a href=\"update.php?LSUserID=" .$row['LSUserID']."\">" .$row['LSUserID']."</a></td>"; 
    echo "<td><a href=\"update.php?LSUserID=" .$row['LSUserID']."\">" .$row['ComputerName']."</a></td>"; 
    echo "<td>" . $row['SerialNumber'] . "</td>"; 
    echo "<td>" . $row['SystemModel'] . "</td>"; 
    echo "<td>" . $row['DateTime'] . "</td>"; 
+1

spreadsheet.xls 파일에 기록 하시겠습니까? 믿거 나 말거나, Excel은 HTML 표를 스프레드 시트로 엽니 다. –

+0

은 csv 파일이 더 좋고 호환성이 뛰어나고 PHP 도구로 작성되었습니다. –

답변

4

당신은 아래의 해당 헤더 (사람이 필요 출신 것이다 PHP는 문서의 example) 그 후

$export = "my_name.xls"; 

header('Pragma: public'); 
///////////////////////////////////////////////////////////// 
// prevent caching.... 
///////////////////////////////////////////////////////////// 
// Date in the past sets the value to already have been expired. 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");  
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); 
header('Cache-Control: no-store, no-cache, must-revalidate');  // HTTP/1.1 
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 
header ("Pragma: no-cache"); 
header("Expires: 0"); 
///////////////////////////////////////////////////////////// 
// end of prevent caching.... 
///////////////////////////////////////////////////////////// 
header('Content-Transfer-Encoding: none'); 
// This should work for IE & Opera 
header('Content-Type: application/vnd.ms-excel;'); 
// This should work for the rest 
header("Content-type: application/x-msexcel");  
header('Content-Disposition: attachment; filename="'.basename($export).'"'); 

, 당신의 코드 (엑셀) HTML 구조를 읽을 수있는 수정의 부부와 함께 작동합니다 :

,691 그래도 문제가 해결되지 않으면
error_reporting (E_ALL^E_NOTICE); // you shouldn't have that in the loop. 
            // you actually should put this first 
echo "<table >" 
    // the rest of your table opening code. 

$alt_color = 0; 
while($row = mysql_fetch_array($result)) 
{ 
    echo "<tr>"; 
    // the rest of your columns. 
    echo "</tr>"; 
} 
echo "</table>"; 

, 어떤 이유로, 당신은 CSV를 만들 수 있습니다,하지만 당신은 그것을 탈출에 대해 걱정할 필요가 :

// add all of the headers. 
echo '"ComputerName","SerialNumber","SystemModel",'; //etc for all columns. 

// row makes sure that there is only one set of values. 
$row = mysql_fetch_row($result); 
if(!$row) die(); // no value found. exit. 
echo getCSVRow($row); 
do // do...while lets us handle the \n more gracefully. 
{ 
    echo "\n". getCSVRow($row); 
} while ($row = mysql_fetch_row($result)); 

function getCSVRow(array $row) 
{ 
    $ret = ""; 
    foreach($row as $val) 
     $ret .= '"' . escapeCSV($val) . '",'; 
    return sustr($ret, 0, strlen($ret)); // clear the tailing comma 
} 

function escapeCSV($str) 
{ 
    return str_replace('"', '\"', $str); 
} 
1

내가 많이 PHP/MySQL을의 환경에서 데이터베이스 수출을 만들기 위해 구글의 AppInventor에서 영감 도구를 발견했다. http://www.freegroup.de/software/phpBlocks/demo.html

+0

약간의 설명이 더 명확해야하지만 링크가 유효한 소프트웨어 기술로가는 것 같습니다. @ Andreas는 일반적으로 링크 스팸 봇 (linkspam bot)의 유행 때문에 스택 오버플로에서 특히 링크를 시작하는 것 이상으로 게시물을 작성해야합니다. – Kzqai

0

phpBlock을 사용하면 MIT의 OpenBlock이나 Google의 AppInventor에서 영감을 얻은 드래그 드롭 환경에서 db-> excel 내보내기를 만들 수 있습니다. 이것은 PHP에서 아무것도 코딩 할 필요가 없다는 것을 의미합니다.

하지만 내보내기 기능은 php-lib의 한 가지 가능성 일뿐입니다. 이 lib를 기존 PHP 응용 프로그램의 동적 확장으로 사용할 수 있습니다. 딘처럼. 수식 또는 계산. 이전에 게시 한 것보다 더 명확 해 주시기 바랍니다.