Documents for Excel, Java Edition Documentation
Features / Shapes And Pictures / Linked Picture
In This Topic
    Linked Picture
    In This Topic

    Linked Picture, also known as Camera shape or picture, refers to a real-time dynamic snapshot of the copied range. That is, as values in the copied cell range change, the same is automatically reflected in its snapshot as well. In Microsoft Excel, this feature is provided through Special Paste option named "Linked Picture". This feature is especially useful in case of dashboards and reports as you can display dynamically changing images and can even resize them according to the available space.

    GcExcel Java allows you to create these dynamic linked pictures through addCameraPicture method of the IShape interface. This method accepts the source range of the linked picture and position coordinates of the target range with respect to the document as parameters. As the linked picture is also just another picture, it can be resized and formatted similar to any other picture.

    Java
    Copy Code
    Workbook workbook = new Workbook();
    workbook.getActiveSheet().getRange("A1").getInterior().setColor(Color.GetBlue());
    workbook.getActiveSheet().getRange("B5").getInterior().setColor(Color.GetYellow());
    //Add linked picture
    IShape shape = workbook.getActiveSheet().getShapes().addCameraPicture("=$A$1:$B$4", 100, 100);
    
    workbook.save("LinkedPicture.xlsx");

    Format Linked Picture

    You can set whether the linked picture should display with a transparent background by setting the IPictureFormat.setTransparentBackground method to true.

    Java
    Copy Code
    // Set transparent background
    shape.getPictureFormat().setTransparentBackground(true);
    // Set degree of transparency
    shape.getPictureFormat().setTransparency(0.8);

    You can also convert a linked picture to a usual static picture by setting the IPictureFormat.setReference method to null. Whereas, when this property is set to a reference for a normal picture, it is converted into a linked picture. For detailed implementation of converting a normal picture to a linked picture or vice versa, see online demo.