Ask Your Question
0

How to Automate Image Insert Into Calc

asked 2016-06-29 21:50:13 +0100

dCipher gravatar image

updated 2016-06-30 21:33:56 +0100

Hi

I am trying to automate the insertion of an image into a spreadsheet using the following code. However the image is not inserted so I am wondering where I have made a mistake. In addition I would like to insert 5 new rows into the top of the spreadsheet so that not data appears behind the image. Everything works fine if I use the LibreOffice application but not when I try to automate the procedure.

Thanks, Simon

lo=CreateObject("cusBizobj")
lo.oMergeSrvMgr=CreateObject("com.sun.star.ServiceManager")
lo.oMerge=lo.oMergeSrvMgr.createInstance("com.sun.star.frame.Desktop")
Dimension laArgs(2)
laArgs(1)=lo.oMergeSrvMgr.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laArgs(1).Name="ReadOnly"
laArgs(1).Value=.N.
laArgs(2)=lo.oMergeSrvMgr.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laArgs(2).Name="Hidden"
laArgs(2).Value=.T.
ComArray(lo.oMerge,10)  && convert VFP arrays to COM compatible array
lo.oMergeDoc=lo.oMerge.loadComponentFromURL(ConvertToURL("D:\KardTech\Exp\Leder.xls"),"_blank",0,@laArgs)

loSheet=lo.oMergeDoc.getSheets().getByIndex(0)
loPage=loSheet.DrawPage()

loImg=lo.oMergeDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") 
loImg.GraphicURL = convertToURL("D:\KardTech\Img\Logo.png")

loPos = lo.oMergeSrvMgr.Bridge_GetStruct("com.sun.star.awt.Point")
loPos.X = 0
loPos.Y = 0

loSize = lo.oMergeSrvMgr.Bridge_GetStruct("com.sun.star.awt.Size")
loSize.Width = 150
loSize.Height = 103

loImg.Position=loPos
loImg.Size=loSize
loImg.Name="Logo"

loPage.Add(loImg)

Dimension laArgs(1)

lo.oMergeDoc.getCurrentController().getFrame().getContainerWindow().setVisible(.T.) && View SpreadSheet

laArgs(1)=lo.oMergeSrvMgr.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
laArgs(1).Name="FilterName"
laArgs(1).Value="MS Excel 97"
ComArray(lo.oMergeDoc,10) 

lo.oMergeDoc.storeToURL(ConvertToURL("D:\KardTech\Exp\New.xls"),@laArgs)

lo.oMergeDoc.close(1)
lo.oMerge.Terminate()
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2016-07-01 04:43:46 +0100

mauricio gravatar image

the units for the size is hundredths millimeters

loSize.Width = 1500
loSize.Height = 1030

Best regards

edit flag offensive delete link more
0

answered 2016-06-30 21:29:20 +0100

dCipher gravatar image

updated 2016-06-30 21:29:47 +0100

Actually the above code did work. The problem was with the size of the image. I made the image so small I could not easily see it. So have adjusted the size to make it visible. The image was inserted as a link instead of directly so I will have to change the code because the document has to be portable.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-06-29 21:50:13 +0100

Seen: 169 times

Last updated: Jul 01 '16