Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue1281, ignore missing calcChain part #1288

Merged
merged 3 commits into from
Jan 6, 2023
Merged
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: 9 additions & 10 deletions src/DocumentFormat.OpenXml.Framework/Packaging/OpenSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace DocumentFormat.OpenXml.Packaging
/// </summary>
public class OpenSettings
{
private bool? _autoSave;
private MarkupCompatibilityProcessSettings? _mcSettings;

/// <summary>
Expand All @@ -32,17 +31,14 @@ internal OpenSettings(OpenSettings? other)
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = other.MarkupCompatibilityProcessSettings.TargetFileFormatVersions;
MaxCharactersInPart = other.MaxCharactersInPart;
RelationshipErrorHandlerFactory = other.RelationshipErrorHandlerFactory;
IgnoreExceptionOnCalcChainPartMissing = other.IgnoreExceptionOnCalcChainPartMissing;
}

/// <summary>
/// Gets or sets a value indicating whether to auto save document modifications.
/// The default value is true.
/// </summary>
public bool AutoSave
{
get => _autoSave ?? true;
set => _autoSave = value;
}
public bool AutoSave { get; set; } = true;

/// <summary>
/// Gets or sets the value of the markup compatibility processing mode.
Expand All @@ -51,10 +47,7 @@ public MarkupCompatibilityProcessSettings MarkupCompatibilityProcessSettings
{
get
{
if (_mcSettings is null)
{
_mcSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.NoProcess, FileFormatVersions.Office2007);
}
_mcSettings ??= new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.NoProcess, FileFormatVersions.Office2007);

return _mcSettings;
}
Expand All @@ -77,5 +70,11 @@ public MarkupCompatibilityProcessSettings MarkupCompatibilityProcessSettings
/// Gets or sets a delegate that is used to create a handler to rewrite relationships that are malformed. On platforms after .NET 4.5, <see cref="Uri"/> parsing will fail on malformed strings.
/// </summary>
public Func<OpenXmlPackage, RelationshipErrorHandler>? RelationshipErrorHandlerFactory { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to ignore an exception if the calcChain part is missing.
/// The default value is false which means missing calcChain part will throw an exception upon package open.
/// </summary>
public bool IgnoreExceptionOnCalcChainPartMissing { get; set; }
mikeebowen marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,18 @@ internal OpenXmlPart CreateOpenXmlPart(string relationshipType)
/// <param name="loadedParts">Temp collection to detect loaded (shared) parts.</param>
internal void LoadReferencedPartsAndRelationships(OpenXmlPackage openXmlPackage, OpenXmlPart? sourcePart, RelationshipCollection relationshipCollection, Dictionary<Uri, OpenXmlPart> loadedParts)
{
foreach (var relationship in relationshipCollection)
Dictionary<string, bool> partsToIgnore = new()
{
// Fix bug https://github.com/OfficeDev/Open-XML-SDK/issues/1205
if (relationship.RelationshipType == @"http://schemas.microsoft.com/office/2006/relationships/recovered")
{ @"http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain", openXmlPackage.OpenSettings.IgnoreExceptionOnCalcChainPartMissing },

// Fix bug https://github.com/OfficeDev/Open-XML-SDK/issues/1205
{ @"http://schemas.microsoft.com/office/2006/relationships/recovered", true },
};

foreach (var relationship in relationshipCollection)
{
if (partsToIgnore.ContainsKey(relationship.RelationshipType) && partsToIgnore[relationship.RelationshipType])
{
continue;
}
Expand Down