Add new Worksheet at the lst in Excel VSTO C#
I am working on building an excel Add-In for a few back-end operations. In a few scenarios, I need to create new worksheets dynamically and populate data and chart reports. I am able to add a new worksheet. But the requirement is, The new worksheet should add the last of all existing worksheets.
The code snipped to add new worksheet
Globals.ThisWorkbook.Worksheets.Add()
The above code adding sheet in the beginning.
There is overloaded Add() methiod with parametes
Globals.ThisWorkbook.Worksheets.Add(Before:. After:, Count:, Type)
It is not mandatory to provide default values for all parameters. The code snipped to add a new worksheet at last in the active workbook
int worksheetsCount = Globals.ThisWorkbook.Worksheets.Count;
Globals.ThisWorkbook.Worksheets.Add(After: Globals.ThisWorkbook.Worksheets[worksheetsCount])The code snipped to add a new worksheet at first in the active workbook
int worksheetsCount = Globals.ThisWorkbook.Worksheets.Count;
Globals.ThisWorkbook.Worksheets.Add(Before: Globals.ThisWorkbook.Worksheets[1])