Show or Hide in Excel Document
30 Aug 202416 minutes to read
Show Row and Column
The following code example illustrates how to show hidden row and column in an Excel worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet worksheet = workbook.Worksheets[0];
//Show row and column
worksheet.ShowRow(2, true);
worksheet.ShowColumn(2, true);
//Saving the workbook as stream
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
//Show row and column
worksheet.ShowRow(2, true);
worksheet.ShowColumn(2, true);
//Save the workbook
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
Dim worksheet As IWorksheet = workbook.Worksheets(0)
'Show row and column
worksheet.ShowRow(2, True)
worksheet.ShowColumn(2, True)
'Save the workbook
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to show hidden row and column in an Excel worksheet using C# is present on this GitHub page.
Hide Row and Column
The following code example illustrates how to hide row and column in an Excel worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet worksheet = workbook.Worksheets[0];
//Hide row and column
worksheet.HideRow(2);
worksheet.HideColumn(2);
//Saving the workbook as stream
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
//Hide row and column
worksheet.HideRow(2);
worksheet.HideColumn(2);
//Save the workbook
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
Dim worksheet As IWorksheet = workbook.Worksheets(0)
'Hide row and column
worksheet.HideRow(2)
worksheet.HideColumn(2)
'Save the workbook
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to hide row and column in an Excel worksheet using C# is present on this GitHub page.
Show or Hide Worksheet
The following code example illustrates how to hide the worksheets using Visibility property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(2);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "visibility";
//Set visibility
sheet.Visibility = WorksheetVisibility.Hidden;
//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(2);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "visibility";
//Set visibility
sheet.Visibility = WorksheetVisibility.Hidden;
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Create(2)
Dim sheet As IWorksheet = workbook.Worksheets(0)
sheet.Range("A1:M20").Text = "Visibility"
'Set visibility
sheet.Visibility = WorksheetVisibility.Hidden
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to hide an Excel worksheet in C# is present on this GitHub page.
Show or Hide Grid Lines
The following code example illustrates how to hide the grid lines using IsGridLinesVisible property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "Gridlines";
//Hide grid line
sheet.IsGridLinesVisible = false;
//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "Gridlines";
//Hide grid line
sheet.IsGridLinesVisible = false;
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Create(1)
Dim sheet As IWorksheet = workbook.Worksheets(0)
sheet.Range("A1:M20").Text = "GridLines"
'Hide grid line
sheet.IsGridLinesVisible = False
'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to hide gridlines in an Excel worksheet in C# is present on this GitHub page.
Show or Hide Row and Column Headers
The following code example illustrates how to hide the row and column headings using the IsRowColumnHeadersVisible property of IWorksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "RowColumnHeader";
sheet.IsRowColumnHeadersVisible = false;
//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "RowColumnHeader";
sheet.IsRowColumnHeadersVisible = false;
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Create(1)
Dim sheet As IWorksheet = workbook.Worksheets(0)
sheet.Range("A1:M20").Text = "RowColumnHeader"
sheet.IsRowColumnHeadersVisible = False
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to hide row and column headers in an Excel worksheet using C# is present on this GitHub page.
Show or Hide Worksheet Tabs
The following code example illustrates how to hide the worksheet tabs using DisplayWorkbookTabs property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(3);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "Tabs";
//Hide the tab
workbook.DisplayWorkbookTabs = false;
//set the display tab
workbook.DisplayedTab = 2;
//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(3);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "Tabs";
//Hide the tab
workbook.DisplayWorkbookTabs = false;
//set the display tab
workbook.DisplayedTab = 2;
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Create(3)
Dim sheet As IWorksheet = workbook.Worksheets(0)
sheet.Range("A1:M20").Text = "Tabs"
'Hide the tab
workbook.DisplayWorkbookTabs = False
'set the display tab
workbook.DisplayedTab = 2
'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to hide Excel worksheet tab in C# is present on this GitHub page.
Zoom level
The following code example illustrates how to set the zoom level by using Zoom property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "Zoom level";
//set zoom percentage
sheet.Zoom = 70;
//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:M20"].Text = "Zoom level";
//set zoom percentage
sheet.Zoom = 70;
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Create(1)
Dim sheet As IWorksheet = workbook.Worksheets(0)
sheet.Range("A1:M20").Text = "Zoom level"
'set Zoom percentage
sheet.Zoom = 70
'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
A complete working example to set zoom percentage in an Excel worksheet using C# is present on this GitHub page.