read images/graphics in spreadsheet - PHP

This is a discussion on read images/graphics in spreadsheet - PHP ; hi I have to read images from spreadsheet, is it possible to do with php?...

+ Reply to Thread
Results 1 to 3 of 3

read images/graphics in spreadsheet

  1. Default read images/graphics in spreadsheet

    hi

    I have to read images from spreadsheet, is it possible to do with php?


  2. Default Re: read images/graphics in spreadsheet

    On 14 Jul, 16:00, wst...@hotmail.com wrote:
    > hi
    >
    > I have to read images from spreadsheet, is it possible to do with php?



    maybe. It kind of depends what format the spreadsheets are in.

    C.


  3. Default Re: read images/graphics in spreadsheet

    This class will extract the images from an Excel spreadsheet. It uses
    the SaveAs method to convert it to HTML and image files:

    <?

    // Convert an Excel file to HTML using
    // COM.
    //
    // $conv = new ExcelToHtmlConverter;
    // $result = $conv->convert('file.xls', '.');
    //
    // The output directory will contain files.htm
    // and file_files. The supporting files directory
    // will contain any images in the spreadsheet.

    class ExceltoHtmlConverter
    {
    // Export an Excel file to HTML

    function convert($file, $destDir)
    {
    $excel = new COM('excel.sheet');
    $wb = $excel->Application->Workbooks->Open($file);

    $dir = dirname($file);
    $bn = basename($file);
    $dot = strrpos($bn, '.');
    $rn = $dot === false ? $bn : substr($bn, 0, $dot);

    $htmlPath = "$destDir/$rn.htm";
    $this->removePath($htmlPath);
    $filesPath = "$destDir/${rn}_files";
    $this->removePath($filesPath);

    $excel->Application->DisplayAlerts = false;
    $res = $wb->SaveAs($htmlPath, 44);
    $wb->Close();
    unset($wb);
    unset($excel);
    if (!$res) {
    throw new Exception("Failed to export $file to " .
    "HTML.");
    }
    $images = $this->findImages($filesPath);
    return array('html' => $htmlPath,
    'files' => $filesPath, 'images' => $images);
    }

    // Find image files in the output directory

    function findImages($path)
    {
    $images = array();
    if (is_file($path) || is_link($path)) {
    $ext = strval(substr(strrchr($path, '.'), 1));
    $exts = array('png', 'gif', 'jpg', 'jpeg', 'jpe',
    'tif', 'tiff', 'bmp');
    if (in_array($ext, $exts)) {
    $images[] = $path;
    }
    } else {
    if (($dir = opendir($path)) === false) {
    throw new Exception("Failed to open $path");
    }
    $e = null;
    while (($file = readdir($dir)) !== false) {
    if ($file == '.' || $file == '..') continue;
    try {
    $subs = $this->findImages("$path/$file");
    $images = array_merge($images, $subs);
    } catch (Exception $e) {
    break;
    }
    }
    closedir($dir);
    if (!is_null($e)) {
    throw $e;
    }
    }
    return $images;
    }

    // Remove a file or directory tree

    function removePath($path)
    {
    if (is_file($path) || is_link($path)) {
    if (!unlink($path)) {
    throw new Exception("Failed to unlink $path");
    }
    } elseif (file_exists($path)) {
    if (($dir = opendir($path)) === false) {
    throw new Exception("Failed to open $path");
    }
    $e = null;
    while (($file = readdir($dir)) !== false) {
    if ($file == '.' || $file == '..') continue;
    try {
    $this->removePath("$path/$file");
    } catch (Exception $e) {
    break;
    }
    }
    closedir($dir);
    if (!is_null($e)) {
    throw $e;
    }
    if (!rmdir($path)) {
    throw new Exception("Failed to remove $path");
    }
    }
    }

    // Test using file.xls in the current directory

    function test()
    {
    $dir = dirname(__FILE__);
    $path = "$dir/file.xls";
    $conv = new ExcelToHtmlConverter;
    $result = $conv->convert($path, $dir);

    echo "Converted Excel file $path to HTML.\n";
    echo "HTML file: {$result['html']}\n";
    echo "Files directory: {$result['files']}\n";
    echo "Images: " . join(', ', $result['images']);
    }
    }

    error_reporting(E_ALL);
    ExcelToHtmlConverter::test();

    ?>

    Other options for Excel:

    o Export to HTML using File -> Save As from MS Excel.

    o Export from OpenOffice.

    o AJP Graphics Exporter - Add-in that exports images from Excel.
    <http://www.andypope.info/vba/gex.htm>

    o XL2GIF Macro - Code that exports images by accessing the Shapes
    directly and using the Chart object's Export method.
    <http://www.mvps.org/dmcritchie/excel/xl2gif.htm>

    o Copy the Shape objects to the clipboard and manipulate it from
    there.
    <http://groups.google.com/group/micro...l.programming/
    browse_frm/thread/de2b1b699fb89c01/fd5f054fa9d6de#fd5f054fa9d6de>
    <http://groups.google.com/group/micro...xcel.charting/
    browse_thread/thread/911fa46e1a10952e/
    6bbac0228f383bf8#6bbac0228f383bf8>

    o PHPExcel - PHP Excel 2007 classes.
    <http://www.codeplex.com/PHPExcel>

    Regards,

    John Peters

    On Jul 14, 10:00 am, wst...@hotmail.com wrote:
    > hi
    >
    > I have to read images from spreadsheet, is it possible to do with php?




+ Reply to Thread

Similar Threads

  1. Re: ANN: Spreadsheet::Read 0.16
    By Application Development in forum Perl
    Replies: 0
    Last Post: 07-04-2006, 08:37 AM
  2. ANN: Spreadsheet::Read 0.16
    By Application Development in forum Perl
    Replies: 0
    Last Post: 07-04-2006, 06:02 AM
  3. ANN: Spreadsheet::Read 0.15
    By Application Development in forum Perl
    Replies: 0
    Last Post: 06-21-2006, 11:40 AM
  4. Problem with Spreadsheet::Read
    By Application Development in forum Perl
    Replies: 5
    Last Post: 06-14-2006, 11:35 AM
  5. Excel:How to read a Spreadsheet name
    By Application Development in forum ODBC
    Replies: 0
    Last Post: 09-16-2004, 08:50 PM