Document Solutions for Excel, Java Edition | Document Solutions
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.

    DsExcel 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. You can also specify the cell range where you want to add the linked picture using another overload of this method. 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 at a specific position
    IShape shape = workbook.getActiveSheet().getShapes().addCameraPicture("=$A$1:$B$4", 100, 100);
    ////Add linked picture at a specific cell range
    IShape shapeRange = workbook.getActiveSheet().getShapes().addCameraPicture("=$A$1:$B$5", worksheet.setRange["G1:H5"]);
            
    workbook.save("LinkedPicture.xlsx");
    Note: The target range and the linked picture to be added must exist in the same worksheet. Otherwise, it results into an InvalidOperationException.

    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.