开发者

Insert image in xls sheet throgh php code

开发者 https://www.devze.com 2023-01-23 02:59 出处:网络
Greetings !! I have to insert a logo(image) on the row[0],column[0].I am using \"Spreadsheet_Excel_Writer\" for that.i tried its insertBitmap() methode ,program working fine but it doesn\'t show the b

Greetings !! I have to insert a logo(image) on the row[0],column[0].I am using "Spreadsheet_Excel_Writer" for that.i tried its insertBitmap() methode ,program working fine but it doesn't show the bitmap image on xls sheet,instead blank row. what could be reason ? can you please let me know the exact string format for the argument. Is there any other way to insert image on xls sheet using PHP5.i am very new to php ,it will be a great help .

Have a nice time ahead !!

[edit] Here is the code, as per Aman's comment below:

$sew =& new Spreadsheet_Excel_Writer ();
$worksheet =& $sew->addWorksheet (substr (strval ($name).strval ($sht), 0, 31));
$worksheet->insertBitmap ($row,$col,$image,$x,开发者_开发技巧$y,$scale_x,$scale_y);


I never could get Spreadsheet_Excel_Writer to work properly with image insertions. Not sure if it's a bug in the library or what. But in any case, S_E_W is hideously outdated, you should switch to PHPExcel instead, which supports recent Excel formats (including .xlsx) for reading AND writing, whereas S_E_W is limited to BIFF 5.0, which is Excel '95 (or thereabouts) and only supports writing.


I've just ran a test using Spreadsheet_Excel_Writer. SEW saves the excel file using BIFF5 format. Open Office Calc will read images from BIFF8, but not from BIFF5 files.

EDIT

Further testing:

Setting SEW to write BIFF8 by using $workbook->setVersion(8); still doesn't write the bitmap image correctly as a BIFF8 file. It would seem that unless you want to rewrite SEW to store images correctly for BIFF8, then you won't see them when opening the file in OOCalc... without reading through the OOCalc or SEW code, I couldn't say what the problem is. Nor does Gnumeric read the image when the file is saved as BIFF5, but it will display the image correctly when the file is saved as BIFF8.


I've gotten this to work. The thing is, this writer is EXTREMELY sensitive to cell overwriting.

Your syntax is correct.

Things to look out for:

  • Make sure the file is 24 bit BMP. That's the only thing this writer supports.
  • Make sure nothing overwrites the cell where you place the image.
  • Make sure that the image path is correct.
  • And make sure the scale is set. If it's not set, it goes to 0 which doesn't display the image. The default is noted as 1, but it's not.
0

精彩评论

暂无评论...
验证码 换一张
取 消