File tree Expand file tree Collapse file tree 4 files changed +33
-0
lines changed
Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1127,14 +1127,33 @@ public bool Date1904
11271127 }
11281128 }
11291129
1130+ private const string StrictSpreadsheetMainNamespace = "http://purl.oclc.org/ooxml/spreadsheetml/main" ;
1131+
1132+ // Call this when loading the workbook XML
1133+ private void ValidateWorkbookNamespace ( )
1134+ {
1135+ string defaultNamespace = _workbookXml . DocumentElement . NamespaceURI ;
1136+ if ( defaultNamespace == StrictSpreadsheetMainNamespace )
1137+ {
1138+ throw new NotSupportedException (
1139+ "The workbook is saved in the \" Strict Open XML Spreadsheet\" format, " +
1140+ "which is not supported by EPPlus. " +
1141+ "Please re-save the workbook as a regular \" Excel Workbook (.xlsx)\" " +
1142+ "in the Save As dialog and try again." ) ;
1143+ }
1144+ }
1145+
11301146
11311147 /// <summary>
11321148 /// Create or read the XML for the workbook.
11331149 /// </summary>
11341150 private void CreateWorkbookXml ( XmlNamespaceManager namespaceManager )
11351151 {
11361152 if ( _package . ZipPackage . PartExists ( WorkbookUri ) )
1153+ {
11371154 _workbookXml = _package . GetXmlFromUri ( WorkbookUri ) ;
1155+ ValidateWorkbookNamespace ( ) ;
1156+ }
11381157 else
11391158 {
11401159 // create a new workbook part and add to the package
Original file line number Diff line number Diff line change 250250 <None Update =" Workbooks\SignedWorkbook1.xlsm" >
251251 <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
252252 </None >
253+ <None Update =" Workbooks\StrictOpenXml.xlsx" >
254+ <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
255+ </None >
253256 <None Update =" Workbooks\SubtotalFilters.xlsx" >
254257 <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
255258 </None >
Original file line number Diff line number Diff line change @@ -1130,5 +1130,16 @@ public void InsertAndShift_ShouldNotThrow_WhenArrayIsFull()
11301130 sheet . InsertColumn ( 5 , 1 ) ;
11311131 }
11321132
1133+ [ TestMethod ]
1134+ public void Issue2325 ( )
1135+ {
1136+ var ex = Assert . ThrowsExactly < NotSupportedException > ( ( ) =>
1137+ {
1138+ var package = OpenTemplatePackage ( "StrictOpenXml.xlsx" ) ;
1139+ var ws = package . Workbook . Worksheets . First ( ) ;
1140+ } ) ;
1141+ Assert . IsTrue ( ex . Message . Contains ( "Strict Open XML" ) ) ;
1142+ }
1143+
11331144 }
11341145}
You can’t perform that action at this time.
0 commit comments