Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract picture from Excel sheet

Status
Not open for further replies.

raspoutine

Programmer
Sep 28, 2001
13
FR
Hello Everyone.
I have to convert Excel spreadsheets and transfer them into foxpro table.
For the extraction of data I have no problems. I just have a problem for retrieve photos that are in each Excel sheet and save them on my hard drive.
Can anyone help me?
 
I just did add a grphic into an excel to see, if something is possible from inside excel itself. But after embedding the graphic and selecting it, I don't find a functionality to save that image to disc.

That may not be very thoroughly checking the possibilities, but I think there is no such option even from within the excel application.

Perhaps rather ask excel experts how to do that with a vba macro, then you can also trigger that from foxpro.

Bye, Olaf.
 
I just did the same as Olaf, with the same result.

The worksheet has a Pictures collection, so you can get an object reference to a picture, like so:

Code:
loPicture = loWorksheet.Pictures(1)

Also, the Picture object has a SaveAs method (according to Intellisense):

Code:
loPicture.SaveAs("MyPicture.jpg")

But that produces an OLE error. I can't find any relevant information in the VBA Help.

I suspect it can't be done.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Got it.

What you do is to save the worksheet as a web page (use the workbook's SaveAs method). The pictures will all be placed in a folder, below the one to which you save the workbook.

In my test, they are all JPGs, with names like IMAGE001.JPG, plus there's an XLM file that contains the names of the individual files.

You should be able to use that as a starting point.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Just to add ....

The FileFormat parameter for the SaveAs command is 44. So you need to do this:

Code:
oWorksheet.SaveAs("c:\data\Test.htm", 44)

This will create a folder named Test_Files, below the c:\data folder (in this example).

You can then use ADIR() to loop through the files in that folder. For each file, use APPEND GENERAL to store the picture in your FoxPro table. Or, preferably, keep the files where they are and just store the filenames.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Nice thought, Mike.

I wouldn't have thought of saving as html. That could also be an option for Word.docs etc.

I have used the structure of docx, xlsx, etc to extract images simply by addin .zip extension and unzipping. It didn't occur to me you can use the save to html feature to get at the inner structure of the documents including image files, although it should hae occured to me.

Maybe things have to be more complex for me to understand ;), that's just too simple.

Bye, Olaf.
 
This has been a FAQ in the Word community for years, and Save As HTML is the usual answer given.

You're right, Olaf, that the newer file formats being ZIP files in drag provide other possibilities. That's one of the reasons for the new format. But for "mere mortal" end users, the Save As HTML is still the lesser of the evils.

Note that Word (and presumably Excel) reduces size and resolution as needed when an image is embedded so you might actually get an image of limited use.
 
Oh, shucks. Here was me thinking I had a rare flash of genius.

Well, to be honest, I was always surprised to see how often the question comes up.

When Word first *got* save as HTML I tried it out a couple of times, just enough to learn to NEVER EVER EVER USE WORD FOR HTML. <g> But I did note how it coughs up embedded images.
 
I'm back
I tried the procedure suggested by,Mike Lewis and my problem is solved.
Thank you all for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top