Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/EPPlus/ExcelWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,14 +1127,33 @@ public bool Date1904
}
}

private const string StrictSpreadsheetMainNamespace = "http://purl.oclc.org/ooxml/spreadsheetml/main";

// Call this when loading the workbook XML
private void ValidateWorkbookNamespace()
{
string defaultNamespace = _workbookXml.DocumentElement.NamespaceURI;
if (defaultNamespace == StrictSpreadsheetMainNamespace)
{
throw new NotSupportedException(
"The workbook is saved in the \"Strict Open XML Spreadsheet\" format, " +
"which is not supported by EPPlus. " +
"Please re-save the workbook as a regular \"Excel Workbook (.xlsx)\" " +
"in the Save As dialog and try again.");
}
}


/// <summary>
/// Create or read the XML for the workbook.
/// </summary>
private void CreateWorkbookXml(XmlNamespaceManager namespaceManager)
{
if (_package.ZipPackage.PartExists(WorkbookUri))
{
_workbookXml = _package.GetXmlFromUri(WorkbookUri);
ValidateWorkbookNamespace();
}
else
{
// create a new workbook part and add to the package
Expand Down
3 changes: 3 additions & 0 deletions src/EPPlusTest/EPPlus.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@
<None Update="Workbooks\SignedWorkbook1.xlsm">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Workbooks\StrictOpenXml.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Workbooks\SubtotalFilters.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
11 changes: 11 additions & 0 deletions src/EPPlusTest/Issues/WorksheetIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,5 +1130,16 @@ public void InsertAndShift_ShouldNotThrow_WhenArrayIsFull()
sheet.InsertColumn(5, 1);
}

[TestMethod]
public void Issue2325()
{
var ex = Assert.ThrowsExactly<NotSupportedException>(() =>
{
var package = OpenTemplatePackage("StrictOpenXml.xlsx");
var ws = package.Workbook.Worksheets.First();
});
Assert.IsTrue(ex.Message.Contains("Strict Open XML"));
}

}
}
Binary file added src/EPPlusTest/Workbooks/StrictOpenXml.xlsx
Binary file not shown.
Loading