Thursday, September 11, 2014

Setup zoom for active worksheet of the workbook of excel using the VSTO


i was facing a problem with VSTO. i was trying to zoom some specific worksheet in a workbook. after many days i got the solution. here it can be done.

in this situation a workbook has two worksheet. i want to set up zoom 75% for the 2nd worksheet.


Application oXL;
Workbook oWB;
Worksheet oSheet;

oXL = new Application();

oXL.SheetsInNewWorkbook = 2;
//  oXL.ActiveWindow.Zoom = 150; // first i tired this one. but it does not work.
oXL.Visible = false;
oWB = oXL.Workbooks.Add(Missing.Value);


//  work with the worksheets


for (int i = 1; i <= oWB.Worksheets.Count; i++)
                {
                    oSheet =(Worksheet)oWB.Worksheets.get_Item(i);
                    oSheet.Activate();
                    if (i == 2)
                    {
                        oWB.Windows[1].Zoom = 75;
                    }
                }

               oSheet = (Worksheet)oWB.Worksheets.get_Item(1);
              oSheet.Activate();

No comments:

Post a Comment