2012-02-03 86 views
0

PHP for master在这里我有一个小问题,捕获图像数据从php adn html数据库输入到excel。从数据库mysql插入文件图像到excel

这里我用一个表作为其媒体的html:

<?php 
header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=tes.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
?> 
<table> 
<tr> 
<td> Name </ td> 
<td> Address </ td> 
<td> <img src='foto_saya.jpg' width='100px' height='100px'>> </ td> 
</ tr> 
</ table> 

我想问的是在Excel foto_saya图像尺寸的输出列是100x100的 但出来diexcel图像文件的原始大小, 然后我已经使用style = "width: 100px; height: 100px" 仍然不影响任何东西, 也许有人可以帮助我解决这个问题。 谢谢。

+0

我不wuite understant问题 – Mike 2012-02-03 07:55:49

+0

请再次检查我的问题我修好了。 – ukung 2012-02-03 08:05:07

+0

你意识到你并没有真正写出一个Excel文件...你正在编写一个扩展名为.xls的HTML文件.... PHP不会自动将HTML标记转换为一个真正的Excel文件。虽然MS Excel在加载该文件时非常宽容,但并不完美。不要试图用这种方法强制正确性。为什么不考虑写一个真正的Excel文件呢? – 2012-02-04 11:02:53

回答

0

您无法使用style属性配置要在Excel中显示的图像的大小。

如果您希望图像在不使用样式规则的情况下显示特定大小,则需要使用GD图像库调整大小。

这将是这个样子:

<?php 
// The file 
$filename = 'test.png'; 

// Content type 
header('Content-Type: image/jpeg'); 

// Get new dimensions 
list($width, $height) = getimagesize($filename); 
$new_width = 100; // pixels 
$new_height = 100; // pixels 

// Resample 
$image_p = imagecreatetruecolor($new_width, $new_height); 
$image = imagecreatefrompng($filename); 
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

// Output 
imagepng($image_p, 'test-resized.png'); 
?> 

那么你将要使用调整后的图像为HTML代码:

<table> 
<tr> 
<td> Name </ td> 
<td> Address </ td> 
<td> <img src='test-resized.png' width='100px' height='100px'>> </ td> 
</ tr> 
</ table>