Skip to content

Commit

Permalink
Merge pull request #37 from sergey-tihon/feat/chart-styles
Browse files Browse the repository at this point in the history
Fix: copy Chart Style Parts in FluentPresentationBuilder
  • Loading branch information
sergey-tihon authored Oct 7, 2021
2 parents 0ce2ed4 + 576c6d6 commit e0da582
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Clippit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
paket.dependencies = paket.dependencies
README.md = README.md
docs\RELEASE_NOTES.md = docs\RELEASE_NOTES.md
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
EndProject
Global
Expand Down
29 changes: 28 additions & 1 deletion OpenXmlPowerTools/PowerPoint/PresentationBuilderTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,41 @@ internal static void CopyChartObjects(ChartPart oldChart, ChartPart newChart)
else
{
//ExternalRelationship oldRelationship = oldChart.GetExternalRelationship(relId);
var newRid = NewRelationshipId();
var oldRel = oldChart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (oldRel is null)
throw new PresentationBuilderInternalException("Internal Error 0007");

var newRid = NewRelationshipId();
newChart.AddExternalRelationship(oldRel.RelationshipType, oldRel.Uri, newRid);
dataReference.Attribute(R.id).Set(newRid);
}
}

foreach (var idPartPair in oldChart.Parts)
{
switch (idPartPair.OpenXmlPart)
{
case ThemeOverridePart oldThemeOverridePart:
CopyPart(oldThemeOverridePart);
break;
case ChartColorStylePart oldChartColorStylePart:
CopyPart(oldChartColorStylePart);
break;
case ChartStylePart oldChartColorStylePart:
CopyPart(oldChartColorStylePart);
break;
}
}

void CopyPart<T>(T oldPart) where T : OpenXmlPart
{
var newRid = NewRelationshipId();
var newPart = newChart.AddNewPart<T>(oldPart.ContentType, newRid);

using var oldStream = oldPart.GetStream(FileMode.Open, FileAccess.Read);
using var newStream = newPart.GetStream(FileMode.Create, FileAccess.ReadWrite);
oldStream.CopyTo(newStream);
}
}

private static void UpdateContent(IEnumerable<XElement> newContent, XName elementToModify, string oldRid, string newRid)
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.7.3 - Oct 7, 2021
- Fixed copy Chart Style Parts in FluentPresentationBuilder

#### 1.7.2 - Aug 23, 2021
- DocumentFormat.OpenXml v2.13.1

Expand Down

0 comments on commit e0da582

Please sign in to comment.