Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
When presenting workbooks to customers, or doing a presentation, it can be useful to hide worksheets in a workbook. A structured approach to spreadsheet modelling suggests that data, formulas and visualizations such as charts are kept on separate sheets. This approach keeps the layout clean and simple and makes the workbook easier to navigate. When presenting results, you might want to hide the data or formula sheets from view to avoid distraction.
Users who work in Microsoft Excel, can easily hide and then unhide (show) worksheets. The same features are available to developers who program with Excel spreadsheets. There are different ways of working with spreadsheets from within software applications. One method is to use VSTO, another is Aspose.Cells for .NET.
This article compares hiding and unhiding worksheets with VSTO, using either C# or Visual Basic, to performing the same task with Aspose.Cells, again using either C# or Visual Basic. Aspose.Cells lets you work without Microsoft Excel installed.
The steps to hide a worksheet are:
To unhide a worksheet again, simply toggle visibility on for the hidden sheet.
The code samples below first show how to hide a worksheet. The first samples show the process with VSTO, using either C# or Visual Basic, compared to using Aspose.Cells, again using either C# or Visual Basics.
The second set of code samples show the line used to unhide the worksheet in VSTO or Aspose.Cells.
Below are code samples for VSTO and Aspose.Cells that illustrate how to hide a worksheet in a workbook.
C#
.......
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using System.Reflection;
.......
//Instantiate the Application object.
Excel.Application excelApp = new Excel.ApplicationClass();
//Specify the template Excel file path.
string myPath=@"d:\test\MyBook.xls";
//Open the Excel file.
excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//Get the first sheet.
Excel.Worksheet objSheet = (Excel.Worksheet)excelApp.ActiveWorkbook.Sheets["Sheet1"];
//Hide the worksheet.
objSheet.Visible = Excel.XlSheetVisibility.xlSheetHidden
//Save As the Excel file.
excelApp.ActiveWorkbook.Save();
//Quit the Application.
excelApp.Quit();
C#
.......
using Aspose.Cells;
.......
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Specify the template Excel file path.
string myPath = @"d:\test\MyBook.xls";
//Open the Excel file.
workbook.Open(myPath);
//Get the first sheet.
Aspose.Cells.Worksheet objSheet = workbook.Worksheets["Sheet1"];
//Hide the worksheet.
objSheet.IsVisible = false;
//Save As the Excel file.
workbook.Save(@"d:\test\MyBook.xls");
Below are code samples for VSTO and Aspose.Cells that illustrate how to unhide a worksheet in a workbook.
C#
//Unhide the worksheet.
objSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible;
C#
//Unhide the worksheet.
objSheet.IsVisible = true;
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.