diff --git a/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/Excel/XLWorkbook.cs index 8eaf483..a33adcc 100644 --- a/ClosedXML/Excel/XLWorkbook.cs +++ b/ClosedXML/Excel/XLWorkbook.cs @@ -502,15 +502,23 @@ private static SpreadsheetDocumentType GetSpreadsheetDocumentType(string filePath) { var extension = Path.GetExtension(filePath); - if (extension == null) throw new Exception("Empty extension is not supported."); + extension = extension.Substring(1).ToLowerInvariant(); - if (extension.ToLowerInvariant().Equals(".xlsm")) return SpreadsheetDocumentType.MacroEnabledWorkbook; + switch (extension) + { + case "xlsm": + case "xltm": + return SpreadsheetDocumentType.MacroEnabledWorkbook; + case "xlsx": + case "xltx": + return SpreadsheetDocumentType.Workbook; + default: + throw new ArgumentException(String.Format("Extension '{0}' is not supported. Supported extensions are '.xlsx', '.xslm', '.xltx' and '.xltm'.", extension)); - if (extension.ToLowerInvariant().Equals(".xlsx")) return SpreadsheetDocumentType.Workbook; - - throw new Exception(String.Format("Extension '{0}' is not supported. Supported extensions are '.xlsx' and '.xslm'.", extension)); + } } + private void checkForWorksheetsPresent() { if (Worksheets.Count() == 0)