PDA

View Full Version : Picture into Excel using OfficeWebComponents



cman
11-02-2006, 02:00 PM
Im trying to insert a picture into/over a cell on a spreadsheet object using Office Web Components within a web page. I have the Spreadsheet full of data, but am unable to insert the image file into the page. I have been trying to use Activesheet.shapes or .picture . I've read that there are hidden pictures objects, but unable to find information about it. Seems like there should be a way to insert the picture into a cell within my loops. I just cant figure out how to reference the file and the syntax to insert the picture into that cell??? Help! :banghead:

Thanks,
~Craig

mdmackillop
11-02-2006, 02:40 PM
Hi Craig,
Welcome to VBAX,
Can you post the code that you're using?
Regards
MD

cman
11-02-2006, 03:11 PM
For row = 1 to iRows
pig_score = trim(Spreadsheet1.ActiveSheet.Cells(row,pigcol).value)
if instr(pig_score,"-") then
pig_score_array = split(pig_score,"-")
prob = pig_score_array(0)
impact = pig_score_array(1)
score = trim(Spreadsheet1.ActiveSheet.Cells(row,pigscore_col).value)
Select Case score
Case 1
bgcolor="#99C9DF"
pigimg = "icon_pigscore_1.gif"
Case 2
bgcolor="#BEDBA3"
pigimg = "icon_pigscore_2.gif"
Case 3
bgcolor="#F5DB6D"
pigimg = "icon_pigscore_3.gif"
Case 4
bgcolor="#F9CE03"
pigimg = "icon_pigscore_4.gif"
Case 5
bgcolor="#FD6A0A"
pigimg = "icon_pigscore_5.gif"
Case Else
bgcolor="#E6E4E5"
pigimg = "icon_pigscore_default.gif"
End Select

'Spreadsheet1.Shapes(pigimg).Left = Range("J1").Left
'Spreadsheet1.ActiveSheet.Shapes(&pigimg).Left = Range("J&row").Left
'Spreadsheet1.ActiveSheet.Shapes(&pigimg).Top = Range("J&row").Top
'Spreadsheet1.ActiveSheet.Cells(row,pigcol).value = Spreadsheet1.ActiveSheet.Picture = "\excelpic.bmp"
'Spreadsheet1.ActiveSheet.Cells(row,pigcol).value = Spreadsheet1.ActiveSheet.Shapes(12)
'Spreadsheet1.ActiveSheet.Cells(row,pigcol).value = prob & "<img src=""images/" & pigimg & """/>" & impact
'set Spreadsheet1.ActiveSheet.Cells(row,pigcol).HtmlData = prob & "<img src=""images/" & pigimg & """/>" & impact
else
bgcolor="#E6E4E5"
end if
Spreadsheet1.ActiveSheet.Cells(row,pigcol).interior.color = bgcolor
Next

have abunch of stuff commeted out....basically the above just picks an image based on the data, but i cant find the syntax to make the image float above the cell or insert into the cell....

right now i have the background color changed for the necessary color based on the data, but need custom pictures...

cman
11-02-2006, 03:12 PM
thanks for the quick response....

mdmackillop
11-02-2006, 03:35 PM
I don't know anything about the Web stuff, but this should inset a picture with top left at the specified cell

Sub InsertPic()
With ActiveSheet
.Cells(15, 3).Activate
.Pictures.Insert ("C:\AAA\insurance.gif")
End With
End Sub


BTW, If you select your code and click the VBA button, it formats as shown, making it more readable.

johnske
11-02-2006, 05:01 PM
AFAIK, what you're after is simply not an option with an OWC spreadsheet. :)

cman
11-03-2006, 08:39 AM
:banghead: hmmm... that sucks....uh... i read something about using a pivot table or having the picture hover over the cell that makes it look like it is on the cell? seems like there has to be a way to do it.....

cman
11-03-2006, 08:40 AM
thanks again

cman
11-07-2006, 03:05 PM
Do you know anything about this book?
THE MICROSOFT OFFICE WEB COMPONENTS BLACK BOOK W/ .NET
BY Alvin J. Bruney M.V.P
:dunno