Introduction
Scroll bars are very important to navigate the contents of any file. Normally, there are two kinds of scroll bars that are most widely used in all applications and these are:
- Vertical Scroll Bar
- Horizontal Scroll Bar
Microsoft Excel also provides Horizontal & Vertical Scroll Bars to scroll through the contents of the worksheets. Using Aspose.Cells , developers can control the visibility of both of these scroll bars in their Excel files.
Controlling the Visibility of the Scroll Bars
Aspose.Cells provides a class, Workbook that represents an Excel file. Workbook class provides a wide range of properties and methods to manage an Excel file. But, to control the visibility of the scroll bars in the Excel file, developers may use IsVScrollBarVisible & IsHScrollBarVisible properties of the Workbook class. IsVScrollBarVisible & IsHScrollBarVisible are boolean properties, which means that these properties can only store true or false values.
Hiding Scroll Bars
Developers can hide the vertical or horizontal scroll bars of the Excel file by setting the IsVScrollBarVisible or IsHScrollBarVisible property of the Workbook class to false.
Example:
[C#]
//Hiding the vertical scroll bar of the Excel file
workbook.IsVScrollBarVisible=false;
//Hiding the horizontal scroll bar of the Excel file
workbook.IsHScrollBarVisible=false;
[VB.NET]
'Hiding the vertical scroll bar of the Excel file
workbook.IsVScrollBarVisible=False
'Hiding the horizontal scroll bar of the Excel file
workbook.IsHScrollBarVisible=False
[JAVA]
//Hiding the vertical scroll bar of the Excel file
workbook.setVerticalScrollBarHidden(true);
//Hiding the horizontal scroll bar of the Excel file
workbook.setHorizontalScrollBarHidden(true);
Making Scroll Bars Visible
Developers can make the vertical or horizontal scroll bars (of an Excel file) visible by setting the IsVScrollBarVisible or IsHScrollBarVisible property of the Workbook class to true.
Example:
[C#]
//Displaying the vertical scroll bar of the Excel file
workbook.IsVScrollBarVisible = true;
//Displaying the horizontal scroll bar of the Excel file
workbook.IsHScrollBarVisible = true;
[VB.NET]
'Displaying the vertical scroll bar of the Excel file
workbook.IsVScrollBarVisible = True
'Displaying the horizontal scroll bar of the Excel file
workbook.IsHScrollBarVisible = True
[JAVA]
//Displaying the vertical scroll bar of the Excel file
workbook.setVerticalScrollBarHidden(false);
//Displaying the horizontal scroll bar of the Excel file
workbook.setHorizontalScrollBarHidden(false);
Example:
A complete example is given below that opens an Excel file (Book1.xls), makes its both scroll bars hidden and then saves the modified file as output.xls.
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream("C:\\book1.xls",FileMode.Open);
//Opening the Excel file through the file stream
workbook.Open(fstream);
//Hiding the vertical scroll bar of the Excel file
workbook.IsVScrollBarVisible = false;
//Hiding the horizontal scroll bar of the Excel file
workbook.IsHScrollBarVisible = false;
//Saving the modified Excel file in default (that is Excel 2000) format
workbook.Save("C:\\output.xls",FileFormatType.Default);
//Closing the file stream to free all resources
fstream.Close();
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Creating a file stream containing the Excel file to be opened
Dim fstream As FileStream = New FileStream("C:\\book1.xls",FileMode.Open)
'Opening the Excel file through the file stream
workbook.Open(fstream)
'Hiding the vertical scroll bar of the Excel file
workbook.IsVScrollBarVisible=False
'Hiding the horizontal scroll bar of the Excel file
workbook.IsHScrollBarVisible=False
'Saving the modified Excel file in default (that is Excel 2000) format
workbook.Save("C:\\output.xls",FileFormatType.Default)
'Closing the file stream to free all resources
fstream.Close()
[JAVA]
//Instantiating a Excel object
Workbook workbook = new Workbook();
//Opening the Excel file
workbook.open("C:\\book1.xls");
//Hiding the vertical scroll bar of the Excel file
workbook.setVerticalScrollBarHidden(true);
//Hiding the horizontal scroll bar of the Excel file
workbook.setHorizontalScrollBarHidden(true);
//Saving the modified Excel file in default (that is Excel 2000) format
workbook.save("C:\\output.xls");
Excel File - Before Modification
You can see Book1.xls file containing both scroll bars in the figure below:
|
Figure: Excel file before any modification
|
Excel File - After Executing the Example Code
Book1.xls file is opened by calling the Open method of the Workbook class and then the both scroll bars of the Excel file are made hidden. The modified file is saved as output.xls file whose pictorial view is shown below:
|
Figure: Excel file after modification
|