10 Replies Latest reply: Sep 6, 2011 12:22 PM by Dipesh Patel RSS

    Loading images using a macro

      Hi Everyone,


      I'm fairly new to qlikview and with one project under my belt I'm looking at a new one which is a lot more challenging.


      Basically the document will need to retrieve images from a file store on the network based on the criteria set in the list boxes. I can't load the images into the document as there could potentially be thousands of images. I've started playing around to prove this can be done and decided that a macro is the only approach. So far I can click on a value in a listbox and then push a button, this triggers a macro which goes and retrieives the image and displays it in a container for me which is great. I can also do this for multiple images as well now, but I have 2 problems...


      1. I don't know the syntax to set the Image Strech to Keep Aspect (cant seem to find it anywhere for Foreground image

      2. The 2nd, 3rd pics that I load are very blurry and lose quality, if I load the images without a container the quality is perfect


      Below is the Macro I have so far:


      sub OpenPics_Cont

      IMG_PATH = "C:\Users\Public\Pictures\Sample Pictures\"


      Set ContainerObj = ActiveDocument.Sheets("Main").CreateContainer

      set ContProp=ContainerObj.GetProperties


      set LB = ActiveDocument.GetSHeetObject("LB01")



          for i=lbound(pg) to ubound(pg)

              set mytext=ActiveDocument.ActiveSheet.CreateTextObject


              prop.Layout.ImageRepresentation.Presentation = 1

              prop.Layout.Text.v = "='" & IMG_PATH & pg(i) & ".jpg'"


              mytext.SetProperties prop






              ContProp.ContainedObjects.Item(i).Id =prop.Layout.Frame.ObjectId

              ContProp.ContainedObjects.Item(i).Text.v = pg(i)

              ContainerObj.SetProperties ContProp




      end sub


      Does anyone have any idea's how I might be able to adjust the aspect of the image and why the image quality is so bad.

        • Re: Loading images using a macro


          Let's try this for image stretching


          sub Stretch

          set bu=ActiveDocument.GetSheetObject("BU01")

          set prop=bu.GetProperties

          prop.BkImageSettings.ImageStyle.StretchMode=1 'fill

          bu.SetProperties prop

          end sub


          Let me know it works or not



          • Re: Loading images using a macro
            Isaiah Weed

            Have you looked into the INFO functionality built in to QV?  This allows you to link external files to a field value.  Check the help file for the topic "Info"   -Isaiah

              • Re: Loading images using a macro

                @Isiah Weed - I didnt want to use this functionality, wouldnt this make a copy of the image and store it in the qlikview document, maybe I misunderstood how this works? The document is likely to be reloaded twice/thrice a day and will the amount of data will get large quite rapidly.

                  • Re: Loading images using a macro
                    Isaiah Weed

                    With INFO LOAD you only embed the images in the QVW if you use the BUNDLE prefix.  "Regular" INFO LOAD links to the file externally and it is only opened when called.  I have the same issue as you; I would never be able to embed all of the images into my QVW for size constraints.  Try the info load (no bundle) in a small test file and I think you'll be presently surprised.  -Isaiah

                      • Re: Loading images using a macro

                        Thanks Isaiah, I'll give this a try with the example I already have. I'll let you know how I get on with this.

                        • Loading images using a macro

                          Just got back to this now... I tried the info load for the pictures and it works. Thanks a lot. Though it appears Im restricted to viewing one image at a time in a textbox. Which is no big deal the user can see the possible images related to the their criteria in the picture listbox and click each one as they wish, but oout of interest is it possible to view multiple images in multiple textboxes without the use of macros?

                            • Loading images using a macro
                              Isaiah Weed

                              When you say text box I assume you mean a popup window (e.g. you've got a button with action = "Show Information"?)  Or are you actually showing the image inside of a textbox?  Moot point though really; I don't think you'll be able to cycle through the possible values without a macro, although that's not to completely say something couldn't be done.




                              Instead you can create a table box (or straight/pivot table) and adding your field with Info as a dimension.  Then pick "Info as Image" in Advanced Field Settings (this is on the Presentation tab in table box properties.)  Remember to wrap text a few lines.  -Isaiah