472,779 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

read images/graphics in spreadsheet

hi

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

Jul 14 '07 #1
2 3027
C.
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.

Jul 14 '07 #2
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?

Jul 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: CJM | last post by:
I've had some periodic problems on certain (intranet)servers where IIS seems to be caching thing in an unexpected way, or is server cached pages where new content is expected. The first...
7
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application....
3
by: Bob Dydd | last post by:
Hi Everybody I have an Access 2000 db with a setup for inserting images in records. I am using the image path only with the actual images stored elswhere on the hard disc. This works perfectly...
3
by: Fahad Aijaz | last post by:
Can any one tell me how can I create overlapping images using ASP.NET. That is, One rectangle drawn as a background image and then another image is placed over it. If the upper image gets...
12
by: Dr. Zharkov | last post by:
Hello. Inform, please, on what site it is possible to find materials on construction of the three-dimensional graphic of function z=f(x,y) with the help of Visual Basic .NET and GDI+? Beforehand...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
0
by: Jeb Hunter | last post by:
Well, how can I describe this succinctly? I have a page with DIVs that us background images to produce a border effect. It works perfectly well, but I want to make up (for now) 3 different...
4
by: =?Utf-8?B?U3BlZWR5?= | last post by:
Hi there, I am currently writing an application where one inspects images and annotates certain features. Thus, one has to zoom in (4x) and pan around. The features are marked with little red...
7
by: Stephen.Schoenberger | last post by:
Hello, I am reading in a bitmap image and storing it as a bitmap in C#. I need to perform some mathmatical operations on that image but it needs to be broken up into smaller fragments (16x16)....
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.