Sometimes, we may need to change the zoom factor when displaying the data on the excel worksheet to fulfil our requirements. In this article, we will demonstrate how to set the zoom factor on Excel work sheet in C# with the help of Spire.XLS.
Firstly, please view the screenshot of how Microsoft Excel to set the zoom factor after click View--Zoom on the top toolbox:
Spire.XLS enables developers to set the value of worksheet’s zoom property to the specific zoom factor via sheet.Zoom. Here comes to the steps of how to control the zoom factor by Spire.XLS.
Step 1: Create a new Excel workbook and load from file.
Workbook wb = new Workbook(); wb.LoadFromFile("Sample.xlsx");
Step 2: Get the first worksheet from the Excel workbook.
Worksheet sheet = wb.Worksheets[0];
Step 3: Set the value of worksheet's zoom property to the specific zoom factor.
sheet.Zoom = 100;
Step 4: Save the document to file.
wb.SaveToFile("result.xlsx", ExcelVersion.Version2010);
Effective screenshot after setting the zoom factor:
Full codes:
using Spire.Xls; namespace Zoom { class Program { static void Main(string[] args) { Workbook wb = new Workbook(); wb.LoadFromFile("Sample.xlsx"); Worksheet sheet = wb.Worksheets[0]; sheet.Zoom = 100; wb.SaveToFile("result.xlsx", ExcelVersion.Version2010); } } }