//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); var sheet1 = workbook.ActiveSheet; var sheet2 = workbook.Worksheets.Add(); var sheet3 = workbook.Worksheets.Add(); // Select sheet2 and sheet3. workbook.Worksheets[new[] { sheet2.Name, sheet3.Name }].Select(); // Write names of selected sheets to console foreach (var sheet in workbook.SelectedSheets) { Console.WriteLine(sheet.Name); } // Add sheet1 to selected sheets sheet1.Select(replace: false); // Write count of selected sheets to console Console.WriteLine(workbook.SelectedSheets.Count); // Save to an excel file workbook.Save("SelectWorksheets.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim sheet1 = workbook.ActiveSheet Dim sheet2 = workbook.Worksheets.Add Dim sheet3 = workbook.Worksheets.Add ' Select sheet2 and sheet3. workbook.Worksheets({sheet2.Name, sheet3.Name}).Select() ' Write names of selected sheets to console For Each sheet In workbook.SelectedSheets Console.WriteLine(sheet.Name) Next ' Add sheet1 to selected sheets sheet1.Select(replace:=False) ' Write count of selected sheets to console Console.WriteLine(workbook.SelectedSheets.Count) ' save to an excel file workbook.Save("SelectWorksheets.xlsx")