public ExcelWorksheetInstance GetWorksheet(object worksheetName)
        {
            ExcelWorksheet worksheet;

            if (TypeUtilities.IsString(worksheetName))
            {
                var strWorksheetName = TypeConverter.ToString(worksheetName);
                worksheet = m_excelPackage.Workbook.Worksheets.FirstOrDefault(w => w.Name == strWorksheetName);

                if (worksheet == null)
                {
                    throw new JavaScriptException(this.Engine, "Error", "A worksheet with the specified name does not exist.");
                }
            }
            else if (TypeUtilities.IsNumeric(worksheetName))
            {
                var index = TypeConverter.ToInteger(worksheetName);
                worksheet = m_excelPackage.Workbook.Worksheets.ElementAtOrDefault(index);

                if (worksheet == null)
                {
                    throw new JavaScriptException(this.Engine, "Error", "A worksheet at the specified index does not exist.");
                }
            }
            else
            {
                throw new JavaScriptException(this.Engine, "Error",
                                              "The first argument must either be the name or index of a worksheet.");
            }

            var worksheetInstance = new ExcelWorksheetInstance(this.Engine.Object.InstancePrototype, worksheet);

            return(worksheetInstance);
        }
        public ExcelWorksheetInstance AddExisting(string name, ExcelWorksheetInstance worksheet)
        {
            var result = m_excelWorksheets.Add(name, worksheet.ExcelWorksheet);

            return(new ExcelWorksheetInstance(this.Engine.Object.InstancePrototype, result));
        }