[請益] 如何將資料匯入excel?

看板PHP作者 (你還是要幸福......)時間13年前 (2012/05/31 00:01), 編輯推噓0(004)
留言4則, 1人參與, 最新討論串1/1
以下程式碼不是我自己寫的 所以自己一知半解...... 想修改也修得亂七八糟兼頭大....... 輸出到excel這邊有試過加上 header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=php_excel.xls"); 這類的方式 但是就只會把網頁所顯示的圖檔和文字 (亮度調校 對比調校...等等) http://ppt.cc/KROa 直接貼在excel的工作表上 數值資料也都沒有出現 是希望可以改成一次處理多張圖檔 也能把得到的閾值輸出到excel(數字或文字會待在欄位中) 實在是不知道要用甚麼方式解決這個問題 希望有高手能解惑~~~ 謝謝 QQ <?php error_reporting(E_ERROR);header("Content-Type: text/html; charset=utf-8"); if (!is_null($_GET['f'])) { $file = $_GET['f']; } else { $file = "2011_0802_1100"; } if (!is_null($_GET['x'])) { $x = $_GET['x']; } else { $x = 400; } if (!is_null($_GET['y'])) { $y = $_GET['y']; } else { $y = 695; } if (!is_null($_GET['cx'])) { $cx = $_GET['cx']; } else { $cx = 460; } if (!is_null($_GET['cy'])) { $cy = $_GET['cy']; } else { $cy = 125; } if (!is_null($_GET['br'])) { $brightness = $_GET['br']; } else { $brightness = 0; } if (!is_null($_GET['ct'])) { $constrast = $_GET['ct']; } else { $constrast = 0; } if (!is_null($_GET['cr'])) { $cr = $_GET['cr']; } else { $cr = 0; } if (!is_null($_GET['cg'])) { $cg = $_GET['cg']; } else { $cg = 0; } if (!is_null($_GET['cb'])) { $cb = $_GET['cb']; } else { $cb = 0; } $filename = "img/" . $file . ".jpg"; #echo $filename . "\n"; $imInfo = getimagesize($filename); $w = $imInfo[0]; $h = $imInfo[1]; $src = imagecreatefromjpeg($filename); $dst = imagecreatefromjpeg($filename); $msk = imagecreatefrompng("mask.PNG"); imagefilter($msk, IMG_FILTER_NEGATE); #header("Content-Type: image/png"); #imagepng($msk); #return 0; imagefilter($dst, IMG_FILTER_COLORIZE, $cr, $cg, $cb); imagefilter($dst, IMG_FILTER_CONTRAST, $constrast); imagefilter($dst, IMG_FILTER_BRIGHTNESS, $brightness); #imagefilter($msk, IMG_FILTER_COLORIZE, $cr, $cg, $cb); #imagefilter($msk, IMG_FILTER_CONTRAST, $constrast); #imagefilter($msk, IMG_FILTER_BRIGHTNESS, $brightness); #imagecopy($dst, $src, 0, 0, $x, $y, $cx, $cy); imagecopy($dst, $msk, 0, 0, $x, $y, $cx, $cy); imagecopy($dst, $src, 0, $cy, $x, $y, $cx, $cy); $black = imagecolorallocate($dst, 0, 0, 0); $white = imagecolorallocate($dst, 255, 255, 255); $blue = imagecolorallocate($dst, 0, 0, 255); $red = imagecolorallocate($dst, 255, 0, 0); $th = 60; $r=0; $g=0; $b=0; $sqr=0; $sqg=0; $sqb=0; for ($j=0;$j<$cy;$j++) { for ($i=0;$i<$cx;$i++) { $test = imagecolorat($dst, $i, $j); $trgb = imagecolorsforindex($dst, $test); if (($trgb['red']!==0)||($trgb['green']!==0)||($trgb['blue']!==0)) { $am[$i][$j]=FALSE; } else { $am[$i][$j]=TRUE; } } } $pCounter = 0; for ($j=0;$j<$cy;$j++) { for ($i=0;$i<$cx;$i++) { # $test = imagecolorat($dst, $i, $j); # $trgb = imagecolorsforindex($dst, $test); # echo "$i $j\n"; # echo $trgb['red'] . "," . $trgb['green'] . "," . $trgb['blue'] . "\n"; # if (($trgb['red']!==0)||($trgb['green']!==0)||($trgb['blue']!==0)) { # continue; # } # var_dump($test); if ($am[$i][$j]===FALSE) { continue; } $pCounter++; $colorIndex = imagecolorat($dst, $i+$x, $j+$y); $rgba = imagecolorsforindex($dst, $colorIndex); $r += $rgba['red']; $g += $rgba['green']; $b += $rgba['blue']; $sqr+= pow($rgba['red'],2); $sqg+= pow($rgba['green'],2); $sqb+= pow($rgba['blue'],2); # if (($r<=$th)||($g<=$th)||($b<=$th)) { # echo "black\n"; # imagesetpixel($im, $x, $y, $black); # } # else { # echo "white\n"; # imagesetpixel($im, $x, $y, $white); # } # $progress = 100 * ($y * $w + $x) / ($w * $h); # $progress = sprintf("%f%%\r", $progress); # echo $progress; } } $ar = ($r/$pCounter); $ag = ($g/$pCounter); $ab = ($b/$pCounter); $sdr = (sqrt(($sqr / $pCounter) - pow($ar,2))); $sdg = (sqrt(($sqg / $pCounter) - pow($ag,2))); $sdb = (sqrt(($sqb / $pCounter) - pow($ab,2))); if (!is_null($_GET['thr'])) { $thr = $_GET['thr']; } else { $thr = $ar; } if (!is_null($_GET['thg'])) { $thg = $_GET['thg']; } else { $thg = $ag; } if (!is_null($_GET['thb'])) { $thb = $_GET['thb']; } else { $thb = $ab; } /* if (($ab > 40)&&($sdr > 50)) { $thr = $ar + 1.5*$sdr; $thg = $ag + 1.5*$sdg; $thb = $ab + 1.8*$sdb; } else if (($ab > 40)&&($sdr <= 50)) { $thr = $ar + 3 * $sdr; $thg = $ag + 1.5*$sdg; $thb = $ab + 1.5*$sdb; } else { $thr = $ar; $thg = $ag; $thb = $ab; } */ for ($j=0;$j<$cy;$j++) { for ($i=0;$i<$cx;$i++) { if ($am[$i][$j]===FALSE) { continue; } $colorIndex = imagecolorat($dst, $i+$x, $j+$y); $rgba = imagecolorsforindex($dst, $colorIndex); $r = $rgba['red']; $g = $rgba['green']; $b = $rgba['blue']; if (($r<=$thr)||($g<=$thg)||($b<=$thb)) { # echo "black\n"; imagesetpixel($dst, $i, $j, $black); } else { # echo "white\n"; imagesetpixel($dst, $i, $j, $white); } # $progress = 100 * ($y * $w + $x) / ($w * $h); # $progress = sprintf("%f%%\r", $progress); # echo $progress; } } $string1 = "ar=$ar, ag=$ag, ab=$ab"; $string2 = "sdr=$sdr, sdg=$sdg, sdb=$sdb"; imagestring($dst, 20, 0, 250, $string1, $black); imagestring($dst, 20, 0, 275, $string2, $black); imagestring($dst, 20, 5, 105, "Target", $red); imagestring($dst, 20, 5, 230, "Original", $red); #header('Content-Type: image/png'); exec("rm -f tmp/fog_*.png"); imagepng($dst, "tmp/fog" . $file . ".png", 0); $fs = filesize("tmp/fog" . $file . ".png"); while ($fs != filesize("tmp/fog" . $file . ".png")) { sleep(0.1); $fs = filesize("tmp/fog" . $file . ".png"); } #echo $string; #echo "<img src='tmp.png' />"; imagedestroy($msk); imagedestroy($src); imagedestroy($dst); echo "<html>\n"; echo "\t<head>\n"; echo "\t</head>\n"; echo "\t<body>\n"; echo "<table><tr>"; echo "<th>"; echo "\t\t<img width=\"100%\" src=\"" . "tmp/fog" . $file . ".png" . "\"/>\n"; echo "</th>"; echo "<td>"; echo "<form name=\"test\">"; echo "<table><tr>"; echo "<th>檔案名稱</th><td><input type=\"text\" name=\"f\" value=\"$file\"/></td>"; echo "</tr><tr>"; echo "<th>亮度調校</th><td><input type=\"text\" name=\"br\" value=\"$brightness\"/></td>"; echo "</tr><tr>"; echo "<th>對比調校</th><td><input type=\"text\" name=\"ct\" value=\"$constrast\"/></td>"; echo "</tr><tr>"; echo "<th>紅光濾鏡</th><td><input type=\"text\" name=\"cr\" value=\"$cr\"/></td>"; echo "</tr><tr>"; echo "<th>綠光濾鏡</th><td><input type=\"text\" name=\"cg\" value=\"$cg\"/></td>"; echo "</tr><tr>"; echo "<th>藍光濾鏡</th><td><input type=\"text\" name=\"cb\" value=\"$cb\"/></td>"; echo "</tr><tr>"; echo "<th>紅光閾值</th><td><input type=\"text\" name=\"thr\" value=\"$thr\"/></td>"; echo "</tr><tr>"; echo "<th>綠光閾值</th><td><input type=\"text\" name=\"thg\" value=\"$thg\"/></td>"; echo "</tr><tr>"; echo "<th>藍光閾值</th><td><input type=\"text\" name=\"thb\" value=\"$thb\"/></td>"; echo "</tr><tr>"; echo "<th></th><td><input type=\"submit\" name=\"submit\"/></td>"; echo "</tr>"; echo "</form>"; echo "</td>"; echo "</table>"; echo "\t</body>\n"; echo "</html>"; return 0; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.248.130.7 ※ 編輯: chousf 來自: 111.248.130.7 (05/31 00:01)

05/31 04:24, , 1F
一般網頁轉成xls下載也就是如此
05/31 04:24, 1F

05/31 04:24, , 2F
mime type設對,輸出HTML,自然可以偽裝成xls
05/31 04:24, 2F

05/31 04:25, , 3F
你要檢查你輸出的xls到底有沒有包含網頁上的資訊
05/31 04:25, 3F

05/31 04:25, , 4F
很可能一開始就漏掉了
05/31 04:25, 4F
文章代碼(AID): #1FnaH2kq (PHP)
文章代碼(AID): #1FnaH2kq (PHP)