OLE Excel SOS

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

OLE Excel SOS

Postby Tranber44 on Thu Oct 20, 2016 9:53 am

Hello,
I have difficulty understanding the logic of transcription, in Dyalog V15, of macros' Excel 2013, especially for cases which seem to me simple.

Example:
Macro Excel 2013

ActiveSheet.Pictures.Insert("G:\Gestcf20162017\PhotoEnc\20800120802.bmp").Select

That I have transcribe under Dyalog :

⎕WX←1
⍎'ActiveSheet.Pictures.Insert',(∊#.SPhot[I]),'.Select'

with the next result :

⍎SYNTAX ERROR
ActiveSheet.Pictures.Insert('G:\Gestcf20162017\photoenc\20800120802.bmp').Select

Why this error?

Regards
Bertrand Delassus
Tranber44
 
Posts: 34
Joined: Mon Jan 11, 2010 4:46 pm

Re: OLE Excel SOS

Postby DanB|Dyalog on Thu Oct 20, 2016 10:46 pm

Many .Net programs (methods) need the string to be enclosed.

Try adding an "enclose" (⊂) before the string and reordering the parentheses, as in

ActiveSheet.Pictures.(Insert⊂'G:\Gestcf20162017\photoenc\20800120802.bmp').Select
DanB|Dyalog
 

Re: OLE Excel SOS

Postby Tranber44 on Sat Oct 22, 2016 3:30 pm

Hello,

Thank you for having answered my problem but the proposed solution does not work. I tried with ⎕WX←3 but unsuccessfully.

ActiveSheet.Pictures.Insert[⊂'G:\Gestcf20162017\photoenc\20800120802.bmp'].Select

VALUE ERROR

I discourage to find the good formulation.

Regards

Bertrand Delassus
Tranber44
 
Posts: 34
Joined: Mon Jan 11, 2010 4:46 pm

Re: OLE Excel SOS

Postby PGilbert on Mon Oct 24, 2016 2:59 am

Hello, I have tried to make it work with OLE and I could not make it work either. However I have been able to make it work with the Syncfusion assembly as explained here.

Code: Select all
      ⎕using←'Syncfusion.XlsIO,Syncfusion/4.5/Syncfusion.XlsIO.Base.dll'
      excelEngine←⎕new ExcelEngine
      application←excelEngine.Excel
      application.DefaultVersion←ExcelVersion.Excel2013
      workbook←application.Workbooks.Create 1
      worksheet←workbook.Worksheets[0]
      shape←worksheet.Pictures.AddPicture( 1 1 'd:\MyImage.bmp')
      workbook.SaveAs(⊂'d:\MyFile.xlsx')
      workbook.Close ⍬
      excelEngine.Dispose


There is also a namespace on the AplWiki about using the Syncfusion assembly to emulate the Microsoft Excel program here

Regards,

Pierre Gilbert
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: OLE Excel SOS

Postby DanB|Dyalog on Mon Oct 24, 2016 5:34 am

I got it to work with OLE:

I played a bit with this and found that VBA uses
Code: Select all
activesheet.Shapes.AddPicture Filename:="C:\test\desert.jpg", linktofile:=msoFalse,           savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=100, Height:=100
so I tried in APL
Code: Select all
    XL.ActiveSheet.Shapes.AddPicture'C:\Users\danb\Pictures\YUL-YVR\DSC05964.jpg' 0 1 0 0 100 100
and it inserted a 100x100 pixels picture to the top left of my active sheet.
Does that help?
DanB|Dyalog
 


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest