Adding Scroll Bar Control to a Worksheet using Aspose.Cells for Java

Hi Team, @Amjad_Sahi, @shakeel.faiz
I have tried to add the scroll bar control to a worksheet using Aspose.cells java.

I am able to add the scroll bar using the below code.

Shape scrollBar = sheet.getShapes().addShape(MsoDrawingType.SCROLL_BAR, 9, 0, 34, 0, 320, 15);

But here I am not able to add controls for that scroll bar like current value, min, max, Incremental change, Page change.

Could you please provide the way/link to handle the scroll bar controls using Aspose.cells java.

The same could be possible using .NET from the below link.

@prabu759101

Thanks for using Aspose APIs.

Please type cast the Shape object into ScrollBar object as follow and then you will have access to all the properties of ScrollBar object.

Java

ScrollBar scrollbar = (ScrollBar)sh;

Here is the equivalent code in Java for the .NET code present inside the article. However, addScrollBar() method does not exist in Java so we have to use addShape() method to create the Scroll Bar. Rest of the code is same.

Please see the output Excel file generated by the code as well as the screenshot showing the output Scroll Bar.

When you will change the value of cell A1, the Scroll Bar Cursor will also change.

Download Link:
Output Excel File.zip (6.3 KB)

Java

// Instantiate a new Workbook.
Workbook excelbook = new Workbook();

// Get the first worksheet.
Worksheet worksheet = excelbook.getWorksheets().get(0);

// Get the worksheet cells.
Cells cells = worksheet.getCells();

// Input a value into A1 cell.
cells.get("A1").putValue(8);

// Add a scrollbar control.
Shape sh = worksheet.getShapes().addShape(MsoDrawingType.SCROLL_BAR, 0, 0, 1, 0, 125, 20);

ScrollBar scrollbar = (ScrollBar)sh;

// Set the placement type of the scrollbar.
scrollbar.setPlacement(PlacementType.FREE_FLOATING);

// Set the linked cell for the control.
scrollbar.setLinkedCell("A1");

// Set the maximum value.
scrollbar.setMax(20);

// Set the minimum value.
scrollbar.setMin(1);

// Set the incr. change for the control.
scrollbar.setIncrementalChange(1);

// Set the page change attribute.
scrollbar.setPageChange(5);

// Set it 3-D shading.
scrollbar.setShadow(true);

// Save the excel file.
excelbook.save(dirPath + "ScrollBar.xlsx");

Screenshot

Hi @shakeel.faiz,

It’s working fine. Thanks a lot for your help.

Regards
Prabu R

@prabu759101,

Good to know that the suggested code sorted out your issue. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.