diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c33231b2..c47cabc9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Removed obsolete validation logic from v1 of the SDK
- Removed obsoleted methods from 2.x
- Removed mutable properties on OpenXmlAttribute and marked as `readonly`
+- Removed OpenXmlPackage.Close in favor of Dispose method (#1298)
### Fixed
- Fixed incorrect file extensions for vbaProject files (#1292)
diff --git a/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.EMMA.g.cs b/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.EMMA.g.cs
index 906b8f0c9..59186ccec 100644
--- a/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.EMMA.g.cs
+++ b/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.EMMA.g.cs
@@ -406,18 +406,6 @@ public static class EMMA
///
public static readonly XName model_ref = emma + "model-ref";
- ///
- /// Represents the emma:no-input XML attribute.
- ///
- ///
- /// As an XML attribute, it:
- ///
- /// - is contained in the following XML elements: .
- /// - corresponds to the following strongly-typed properties: Interpretation.NoInput.
- ///
- ///
- public static readonly XName no_input = emma + "no-input";
-
///
/// Represents the emma:node XML element.
///
@@ -432,6 +420,18 @@ public static class EMMA
///
public static readonly XName node = emma + "node";
+ ///
+ /// Represents the emma:no-input XML attribute.
+ ///
+ ///
+ /// As an XML attribute, it:
+ ///
+ /// - is contained in the following XML elements: .
+ /// - corresponds to the following strongly-typed properties: Interpretation.NoInput.
+ ///
+ ///
+ public static readonly XName no_input = emma + "no-input";
+
///
/// Represents the emma:offset-to-start XML attributes.
///
diff --git a/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.NoNamespace.g.cs b/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.NoNamespace.g.cs
index 8320a3ea8..1883e128a 100644
--- a/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.NoNamespace.g.cs
+++ b/generated/DocumentFormat.OpenXml.Linq/DocumentFormat.OpenXml.Generator/DocumentFormat.OpenXml.Generator.OpenXmlGenerator/Linq.NoNamespace.g.cs
@@ -22847,18 +22847,6 @@ public static class NoNamespace
///
public static readonly XName z = "z";
- ///
- /// Represents the z-order XML attribute.
- ///
- ///
- /// As an XML attribute, it:
- ///
- /// - is contained in the following XML elements: .
- /// - corresponds to the following strongly-typed properties: ObjectAnchor.ZOrder.
- ///
- ///
- public static readonly XName z_order = "z-order";
-
///
/// Represents the zeroHeight XML attribute.
///
@@ -22967,6 +22955,18 @@ public static class NoNamespace
///
public static readonly XName zoomToFit = "zoomToFit";
+ ///
+ /// Represents the z-order XML attribute.
+ ///
+ ///
+ /// As an XML attribute, it:
+ ///
+ /// - is contained in the following XML elements: .
+ /// - corresponds to the following strongly-typed properties: ObjectAnchor.ZOrder.
+ ///
+ ///
+ public static readonly XName z_order = "z-order";
+
///
/// Represents the zOrderOff XML attribute.
///
diff --git a/samples/PowerPointModernCommentSample/Program.cs b/samples/PowerPointModernCommentSample/Program.cs
index 5104b11d1..a192f64bd 100644
--- a/samples/PowerPointModernCommentSample/Program.cs
+++ b/samples/PowerPointModernCommentSample/Program.cs
@@ -38,64 +38,63 @@ public static void Main(string[] args)
}
// Create a presentation
- PresentationDocument presentationDocument = PowerPointUtils.CreatePresentation(fileInfo.FullName);
-
- // create missing PowerPointAuthorsPart if it is null
- if (presentationDocument?.PresentationPart?.authorsPart is null)
- {
- presentationDocument?.PresentationPart.AddNewPart();
- }
-
- // Add missing AuthorList if it is null
- if (presentationDocument?.PresentationPart?.authorsPart?.AuthorList is null)
+ using (PresentationDocument presentationDocument = PowerPointUtils.CreatePresentation(fileInfo.FullName))
{
- presentationDocument.PresentationPart.authorsPart.AuthorList = new AuthorList();
- }
-
- // In production you will need to retrieve actual user information
- string authorId = string.Concat("{", Guid.NewGuid(), "}");
- presentationDocument.PresentationPart.authorsPart.AuthorList.AddChild(new Author()
- { Id = authorId, Name = "Jose Contoso", Initials = "JC", UserId = "jose@contosot.com::9ed1aa81-8d9b-4a15-b989-8cbbfd4c4b3e", ProviderId = "AD" });
-
- // Get the Id of the slide to add the comment to
- SlideId slideId = presentationDocument.PresentationPart.Presentation.SlideIdList.Elements().First();
-
- Random ran = new Random();
- UInt32Value cid = Convert.ToUInt32(ran.Next(100000000, 999999999));
-
- // Add a comment to the slide
- PowerPointCommentPart powerPointCommentPart = presentationDocument.PresentationPart.SlideParts.First().AddNewPart();
-
- powerPointCommentPart.CommentList = new CommentList(
- new Comment(
- new SlideMonikerList(
- new DocumentMoniker(),
- new SlideMoniker()
- {
- CId = cid,
- SldId = slideId.Id,
- }),
- new TextBodyType(
- new BodyProperties(),
- new ListStyle(),
- new Paragraph(new Run(new Text("Hello World!")))))
+ // create missing PowerPointAuthorsPart if it is null
+ if (presentationDocument?.PresentationPart?.authorsPart is null)
{
- Id = string.Concat("{", Guid.NewGuid(), "}"),
- AuthorId = authorId,
- Created = DateTime.Now,
- });
-
- SlidePart slidePart = presentationDocument.PresentationPart.SlideParts.First();
- Slide slide = slidePart.Slide;
+ presentationDocument?.PresentationPart.AddNewPart();
+ }
- slide.AppendChild(
- new PresentationExtensionList(
- new PresentationExtension(
- new CommentRelationship()
- { Id = slidePart.GetIdOfPart(powerPointCommentPart) })
- { Uri = "{6950BFC3-D8DA-4A85-94F7-54DA5524770B}" }));
-
- presentationDocument.Close();
+ // Add missing AuthorList if it is null
+ if (presentationDocument?.PresentationPart?.authorsPart?.AuthorList is null)
+ {
+ presentationDocument.PresentationPart.authorsPart.AuthorList = new AuthorList();
+ }
+
+ // In production you will need to retrieve actual user information
+ string authorId = string.Concat("{", Guid.NewGuid(), "}");
+ presentationDocument.PresentationPart.authorsPart.AuthorList.AddChild(new Author()
+ { Id = authorId, Name = "Jose Contoso", Initials = "JC", UserId = "jose@contosot.com::9ed1aa81-8d9b-4a15-b989-8cbbfd4c4b3e", ProviderId = "AD" });
+
+ // Get the Id of the slide to add the comment to
+ SlideId slideId = presentationDocument.PresentationPart.Presentation.SlideIdList.Elements().First();
+
+ Random ran = new Random();
+ UInt32Value cid = Convert.ToUInt32(ran.Next(100000000, 999999999));
+
+ // Add a comment to the slide
+ PowerPointCommentPart powerPointCommentPart = presentationDocument.PresentationPart.SlideParts.First().AddNewPart();
+
+ powerPointCommentPart.CommentList = new CommentList(
+ new Comment(
+ new SlideMonikerList(
+ new DocumentMoniker(),
+ new SlideMoniker()
+ {
+ CId = cid,
+ SldId = slideId.Id,
+ }),
+ new TextBodyType(
+ new BodyProperties(),
+ new ListStyle(),
+ new Paragraph(new Run(new Text("Hello World!")))))
+ {
+ Id = string.Concat("{", Guid.NewGuid(), "}"),
+ AuthorId = authorId,
+ Created = DateTime.Now,
+ });
+
+ SlidePart slidePart = presentationDocument.PresentationPart.SlideParts.First();
+ Slide slide = slidePart.Slide;
+
+ slide.AppendChild(
+ new PresentationExtensionList(
+ new PresentationExtension(
+ new CommentRelationship()
+ { Id = slidePart.GetIdOfPart(powerPointCommentPart) })
+ { Uri = "{6950BFC3-D8DA-4A85-94F7-54DA5524770B}" }));
+ }
}
catch (Exception ex)
{
diff --git a/samples/SunburstChartExample/Program.cs b/samples/SunburstChartExample/Program.cs
index 6d87858d8..ee82218b6 100644
--- a/samples/SunburstChartExample/Program.cs
+++ b/samples/SunburstChartExample/Program.cs
@@ -26,14 +26,15 @@ private static void Main(string[] args)
public static void CreatePresentation(string filepath)
{
// Create a presentation at a specified file path. The presentation document type is pptx, by default.
- var presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation);
- var presentationPart = presentationDoc.AddPresentationPart();
- presentationPart.Presentation = new Presentation();
+ using (PresentationDocument presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation))
+ {
+ var presentationPart = presentationDoc.AddPresentationPart();
+ presentationPart.Presentation = new Presentation();
- CreatePresentationParts(presentationPart);
+ CreatePresentationParts(presentationPart);
- // Close the presentation handle
- presentationDoc.Close();
+ // Close the presentation handle
+ }
}
private static void CreatePresentationParts(PresentationPart presentationPart)
diff --git a/samples/ThreadedCommentExample/Program.cs b/samples/ThreadedCommentExample/Program.cs
index 5d40eed3c..2cafa6b45 100644
--- a/samples/ThreadedCommentExample/Program.cs
+++ b/samples/ThreadedCommentExample/Program.cs
@@ -51,67 +51,65 @@ private static void Main(string[] args)
}
// WORKBOOK
- SpreadsheetDocument? sd = ExampleUtilities.CreateSpreadsheetWorkbook(filePath, sheetName);
-
- if (sd != null)
+ using (SpreadsheetDocument? sd = ExampleUtilities.CreateSpreadsheetWorkbook(filePath, sheetName))
{
- ExampleUtilities.InsertText((SpreadsheetDocument)sd, sheetName, @"Please comment on this cell.", column, row);
- }
+ if (sd != null)
+ {
+ ExampleUtilities.InsertText((SpreadsheetDocument)sd, sheetName, @"Please comment on this cell.", column, row);
+ }
- if (!(sd is null))
- {
- CreateMiscellaneousParts(sd, sheetName);
+ if (!(sd is null))
+ {
+ CreateMiscellaneousParts(sd, sheetName);
- Worksheet? worksheet = ExampleUtilities.GetSheet(sd, sheetName)?.Worksheet;
+ Worksheet? worksheet = ExampleUtilities.GetSheet(sd, sheetName)?.Worksheet;
- if (worksheet != null)
- {
- worksheet.AddChild(new LegacyDrawing() { Id = "rId1" });
+ if (worksheet != null)
+ {
+ worksheet.AddChild(new LegacyDrawing() { Id = "rId1" });
- // NOTE: UserId, DisplayName, Id and ProviderId should be generated by querying the identity server used by this org and account.
- string displayNameUser = "Jose Contoso";
- string idUser = string.Concat("{", System.Guid.NewGuid().ToString().ToUpper(), "}");
- string tcId = string.Concat("{", System.Guid.NewGuid().ToString().ToUpper(), "}");
+ // NOTE: UserId, DisplayName, Id and ProviderId should be generated by querying the identity server used by this org and account.
+ string displayNameUser = "Jose Contoso";
+ string idUser = string.Concat("{", System.Guid.NewGuid().ToString().ToUpper(), "}");
+ string tcId = string.Concat("{", System.Guid.NewGuid().ToString().ToUpper(), "}");
- // For the format of these userId parameter, please refer to [MS-XLSX] 2.6.203 CT_Person
- // This can be a SID from an Active Directory provider, an email address using "PeoplePicker", and O365 id or a simple name.
- string userIdJose = "j.contoso@example.com";
- string providerIdAzure = "PeoplePicker";
+ // For the format of these userId parameter, please refer to [MS-XLSX] 2.6.203 CT_Person
+ // This can be a SID from an Active Directory provider, an email address using "PeoplePicker", and O365 id or a simple name.
+ string userIdJose = "j.contoso@example.com";
+ string providerIdAzure = "PeoplePicker";
- WorkbookPart workbookPart = sd.WorkbookPart ?? sd.AddWorkbookPart();
+ WorkbookPart workbookPart = sd.WorkbookPart ?? sd.AddWorkbookPart();
- WorkbookPersonPart pp = workbookPart.AddNewPart();
+ WorkbookPersonPart pp = workbookPart.AddNewPart();
- pp.PersonList = new PersonList(new Person() { DisplayName = displayNameUser, Id = idUser, UserId = userIdJose, ProviderId = providerIdAzure });
+ pp.PersonList = new PersonList(new Person() { DisplayName = displayNameUser, Id = idUser, UserId = userIdJose, ProviderId = providerIdAzure });
- WorksheetPart wsp = ExampleUtilities.GetSheet(sd, sheetName);
+ WorksheetPart wsp = ExampleUtilities.GetSheet(sd, sheetName);
- WorksheetCommentsPart wscp = wsp.AddNewPart();
- wscp.Comments = new Comments(
- new Authors(
- new Author("tc=" + tcId)), new CommentList(
- new Comment(
- new DocumentFormat.OpenXml.Spreadsheet.CommentText(
- new DocumentFormat.OpenXml.Spreadsheet.Text("Comment: Ok, here's a comment!")))
+ WorksheetCommentsPart wscp = wsp.AddNewPart();
+ wscp.Comments = new Comments(
+ new Authors(
+ new Author("tc=" + tcId)), new CommentList(
+ new Comment(
+ new DocumentFormat.OpenXml.Spreadsheet.CommentText(
+ new DocumentFormat.OpenXml.Spreadsheet.Text("Comment: Ok, here's a comment!")))
- // Comment attributes
- { Reference = reference, AuthorId = 0, ShapeId = 0, Guid = tcId }));
+ // Comment attributes
+ { Reference = reference, AuthorId = 0, ShapeId = 0, Guid = tcId }));
- WorksheetThreadedCommentsPart wstcp = wsp.AddNewPart();
- wstcp.ThreadedComments = new ThreadedComments(
- new ThreadedComment(
- new ThreadedCommentText("Ok, here's a threaded comment!"))
+ WorksheetThreadedCommentsPart wstcp = wsp.AddNewPart();
+ wstcp.ThreadedComments = new ThreadedComments(
+ new ThreadedComment(
+ new ThreadedCommentText("Ok, here's a threaded comment!"))
- // ThreadedComment attributes
- { Ref = reference, PersonId = idUser, Id = tcId, DT = System.DateTime.Now });
+ // ThreadedComment attributes
+ { Ref = reference, PersonId = idUser, Id = tcId, DT = System.DateTime.Now });
+ }
+ }
+ else
+ {
+ throw new Exception("SpreadsheetDocument is null");
}
-
- // Close the document.
- sd.Close();
- }
- else
- {
- throw new Exception("SpreadsheetDocument is null");
}
}
diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/OpenXmlPackage.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/OpenXmlPackage.cs
index d1fb78621..0cd463770 100644
--- a/src/DocumentFormat.OpenXml.Framework/Packaging/OpenXmlPackage.cs
+++ b/src/DocumentFormat.OpenXml.Framework/Packaging/OpenXmlPackage.cs
@@ -143,15 +143,6 @@ public void DeletePartsRecursivelyOfType()
DeletePartsRecursivelyOfTypeBase();
}
- ///
- /// Saves and closes the OpenXml package and all underlying part streams.
- ///
- public void Close()
- {
- ThrowIfObjectDisposed();
- Dispose();
- }
-
#region methods to operate DataPart
///
diff --git a/test/DocumentFormat.OpenXml.Tests/CreateFromTemplateTests.cs b/test/DocumentFormat.OpenXml.Tests/CreateFromTemplateTests.cs
index f2b0f3297..fcd05adf4 100644
--- a/test/DocumentFormat.OpenXml.Tests/CreateFromTemplateTests.cs
+++ b/test/DocumentFormat.OpenXml.Tests/CreateFromTemplateTests.cs
@@ -20,7 +20,7 @@ public void CanCreatePresentationFromTemplate()
var part = packageDocument.PresentationPart;
var root = part.Presentation;
- packageDocument.SaveAs(Path.GetTempFileName()).Close();
+ packageDocument.SaveAs(Path.GetTempFileName()).Dispose();
// We are fine if we have not run into an exception.
Assert.True(true);
@@ -36,7 +36,7 @@ public void CanCreateSpreadsheetFromTemplate()
var part = packageDocument.WorkbookPart;
var root = part.Workbook;
- packageDocument.SaveAs(Path.GetTempFileName()).Close();
+ packageDocument.SaveAs(Path.GetTempFileName()).Dispose();
// We are fine if we have not run into an exception.
Assert.True(true);
@@ -52,7 +52,7 @@ public void CanCreateWordprocessingDocumentFromTemplate()
var part = packageDocument.MainDocumentPart;
var root = part.Document;
- packageDocument.SaveAs(Path.GetTempFileName()).Close();
+ packageDocument.SaveAs(Path.GetTempFileName()).Dispose();
// We are fine if we have not run into an exception.
Assert.True(true);
diff --git a/test/DocumentFormat.OpenXml.Tests/SaveAndCloneTests.cs b/test/DocumentFormat.OpenXml.Tests/SaveAndCloneTests.cs
index 177cb44d5..b26986161 100644
--- a/test/DocumentFormat.OpenXml.Tests/SaveAndCloneTests.cs
+++ b/test/DocumentFormat.OpenXml.Tests/SaveAndCloneTests.cs
@@ -33,7 +33,7 @@ public void CanCloneDocument()
{
var body = clone.MainDocumentPart.Document.Body;
body.InsertBefore(new Paragraph(new Run(new Text("Hello World"))), body.FirstChild);
- clone.SaveAs(file.Path).Close();
+ clone.SaveAs(file.Path).Dispose();
using (var dest = WordprocessingDocument.Open(file.Path, false))
{
@@ -109,14 +109,14 @@ public void CanDoMultithreadedMultipleCloning()
var body3 = clone3.MainDocumentPart.Document.Body;
body3.GetFirstChild()
.InsertBeforeSelf(new Paragraph(new Run(new Text("Clone 3"))));
- clone3.Close();
+ clone3.Dispose();
// Clone source again.
var clone4 = (WordprocessingDocument)source.Clone();
var body4 = clone4.MainDocumentPart.Document.Body;
body4.GetFirstChild()
.InsertBeforeSelf(new Paragraph(new Run(new Text("Clone 4"))));
- clone4.Close();
+ clone4.Dispose();
}
});
}
@@ -181,7 +181,7 @@ public void CanWildlyCloneAndFlush()
using (var tempFile = TemporaryFile.Create())
{
- clone.SaveAs(tempFile.Path).Close();
+ clone.SaveAs(tempFile.Path).Dispose();
}
}
});
@@ -197,7 +197,7 @@ public void CanDoPackageBasedCloningWord()
{
using (var package = Package.Open(ms, FileMode.Create))
{
- source.Clone(package).Close();
+ source.Clone(package).Dispose();
}
ms.Position = 0;
@@ -218,7 +218,7 @@ public void CanDoPackageBasedCloningSpreadsheet()
{
using (var package = Package.Open(ms, FileMode.Create))
{
- source.Clone(package).Close();
+ source.Clone(package).Dispose();
}
ms.Position = 0;
@@ -239,7 +239,7 @@ public void CanDoPackageBasedCloningPowerpoint()
{
using (var package = Package.Open(ms, FileMode.Create))
{
- source.Clone(package).Close();
+ source.Clone(package).Dispose();
}
ms.Position = 0;
diff --git a/test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlValidatorTest.cs b/test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlValidatorTest.cs
index 1346bf689..ee6014d24 100644
--- a/test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlValidatorTest.cs
+++ b/test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlValidatorTest.cs
@@ -3079,8 +3079,6 @@ public void PackageStuctureValidatingTest()
commentsPart.Comments.SaveToPart(commentsPart2);
mainPart.Relationships.Create(mainPart.Uri, System.IO.Packaging.TargetMode.Internal, mainPart.RelationshipType);
-
- wordDoc.Close();
}
stream.Flush();