internal void SaveChanges()
{
if (MainDocumentPart == null) return;
// Serialize the XDocument object back to the package.
using (var xw = XmlWriter.Create(_wordDocument.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write)))
{
MainDocumentPart.Save(xw);
}
if (NumberingPart != null)
{
// Serialize the XDocument object back to the package.
using (var xw = XmlWriter.Create(_wordDocument.MainDocumentPart.NumberingDefinitionsPart.GetStream(FileMode.Create,
FileAccess.Write)))
{
NumberingPart.Save(xw);
}
}
foreach (var footerId in FooterParts.Keys)
{
using (var xw = XmlWriter.Create(_wordDocument.MainDocumentPart.GetPartById(footerId).GetStream(FileMode.Create, FileAccess.Write)))
{
FooterParts[footerId].Save(xw);
}
}
foreach (var headerId in HeaderParts.Keys)
{
using (var xw = XmlWriter.Create(_wordDocument.MainDocumentPart.GetPartById(headerId).GetStream(FileMode.Create, FileAccess.Write)))
{
HeaderParts[headerId].Save(xw);
}
}
_wordDocument.Close();
}