예제 #1
0
        /// <summary>
        /// Gets a worksheetpage by name in a parent folder. If this worksheetpage does not exist, it is created. To get the worksheet page, the parent folder is searched at first by the short name and if unsuccessfull, by the long name of the worksheet page.
        /// </summary>
        /// <param name="parentFolder">The parent folder.</param>
        /// <param name="folderName">Name of the worksheet page to get or create.</param>
        /// <returns>The worksheet page (either previously existing or newly created) of the provided parentFolder, which has the provided name (either as short name, or as long name).</returns>
        public static Origin.WorksheetPage GetOrCreateWorksheetPage(Origin.Folder parentFolder, string worksheetName)
        {
            // test if folder with short folderName is existent
            var worksheet = parentFolder.PageBases[worksheetName] as Origin.WorksheetPage;

            if (null != worksheet)
            {
                return(worksheet);
            }

            // else we must iterate through all Pages and look for a worksheetpage with the same long folder name
            for (int i = 0; i < parentFolder.Folders.Count; ++i)
            {
                worksheet = parentFolder.PageBases[i] as Origin.WorksheetPage;
                if (null != worksheet && worksheet.LongName == worksheetName)
                {
                    return(worksheet);
                }
            }

            // else we create this worksheetpage and return it
            parentFolder.Activate(); // by making the folder active, the worksheet is later created in this folder
            worksheet          = parentFolder.Application.WorksheetPages.Add();
            worksheet.Name     = worksheetName;
            worksheet.LongName = worksheetName;

            return(worksheet);
        }
예제 #2
0
        /// <summary>
        /// Gets a folder by name in a parent folder. If this folder does not exist, it is created. To get the folder, the folder is searched at first by the short name and if unsuccessfull, by the long name.
        /// </summary>
        /// <param name="parentFolder">The parent folder.</param>
        /// <param name="folderName">Name of the folder to get or create.</param>
        /// <returns>The child folder of the provided parentFolder, which has the folderName (either as short name, or as long name).</returns>
        public static Origin.Folder GetOrCreateSingleFolder(Origin.Folder parentFolder, string folderName)
        {
            // test if folder with short folderName is existent
            var folder = parentFolder.Folders[folderName];

            if (null != folder)
            {
                return(folder);
            }

            // else we must iterate through all folders and look for a folder with the same long folder name
            for (int i = 0; i < parentFolder.Folders.Count; ++i)
            {
                folder = parentFolder.Folders[i];
                if (folder.LongName == folderName)
                {
                    return(folder);
                }
            }

            // else we create this folder and return it
            folder          = parentFolder.Folders.Add(folderName);
            folder.LongName = folderName;
            return(folder);
        }