/// <summary> /// Check if a worksheet does exist in a spreadsheet. /// </summary> /// <param name="filepath"> /// Relative/absolute filepath to a *.xlsx file that should be opened. /// </param> /// <param name="worksheetName"> /// Name of the worksheet that should be searched. /// </param> /// <returns> /// True, if worksheet with (parameter) 'worksheetName' does exist, otherwise False. /// </returns> /// <exception cref="FileNotFoundException">Thrown if File was not found</exception> /// <exception cref="UnauthorizedAccessException">Thrown when misssing permission to access File</exception> /// <exception cref="PathTooLongException">Thrown when File-path is too long and path cannot be conveted</exception> /// <exception cref="ArgumentNullException">Thrown when an Argument was or became Null</exception> /// <exception cref="ArgumentException">Thrown when an entred argument was or became invalid</exception> /// <exception cref="InvalidCastException">Thrown when an entered value had an unexpected data-type</exception> /// <exception cref="OpenXmlPackageException">Thrown when exception occurred in the OpenXML-Package</exception> public static bool WorksheetExists(string filepath, string worksheetName) { if (!ExcelIOBase.CheckPathExist(ref filepath)) { return(false); } SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filepath, false); bool isExists = WorksheetExists(ref spreadsheetDocument, worksheetName, out _); spreadsheetDocument.Close(); return(isExists); }
/// <summary> /// Check if a path at the specified (parameter) 'filepath' does exist. /// If the filepath is too long it'll try to access directly to the OS-File-System. /// </summary> /// <param name="filepath"> /// The path to the file that should be searched. /// If the filepath is too long it'll try to access directly to the OS-File-System to search for the file. /// </param> /// <returns> /// True, if the file exists, otherwise false. /// </returns> /// <exception cref="PathTooLongException">Thrown when File-path is too long and path cannot be conveted</exception> public static new bool CheckPathExist(ref string filepath) { return(ExcelIOBase.CheckPathExist(ref filepath)); }