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.
// 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");
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.