Skip to content

Commit

Permalink
It shoul works ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieumack committed Jul 2, 2023
1 parent 3656a48 commit 5fdfbe4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/OpenXMLSDK.Engine/Word/WordManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class WordManager : IDisposable
{
#region Fields

private MemoryStream streamFile;

private string filePath;

/// <summary>
Expand Down Expand Up @@ -121,6 +123,19 @@ wdDoc.MainDocumentPart.Document.Body.LastChild.FirstChild is ParagraphProperties
}
}

/// <summary>
/// Permet de renvoyer le MemoryStream associé au document en cours
/// </summary>
/// <returns>MemoryStream en cours, null sinon</returns>
public MemoryStream GetMemoryStream()
{
var memoryStream = new MemoryStream();
streamFile.Position = 0;
streamFile.CopyTo(memoryStream);
memoryStream.Position = 0;
return memoryStream;
}

#endregion

#region Settings
Expand Down Expand Up @@ -221,9 +236,11 @@ public bool OpenDocFromTemplate(Stream templateFileStream)
if (templateFileStream is null || templateFileStream == Stream.Null)
throw new ArgumentNullException(nameof(templateFileStream), "templateFilePath must not be null");

streamFile = new MemoryStream();
try
{
wdDoc = WordprocessingDocument.Open(templateFileStream, true);
// We copy the template file into the memory stream
templateFileStream.CopyTo(streamFile);

// Change the document type to Document
wdDoc.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
Expand Down Expand Up @@ -251,7 +268,7 @@ public bool OpenDocFromTemplate(string templateFilePath)
if (!File.Exists(templateFilePath))
throw new FileNotFoundException("file not found");

using var streamFile = new MemoryStream();
streamFile = new MemoryStream();
try
{
byte[] byteArray = File.ReadAllBytes(templateFilePath);
Expand Down

0 comments on commit 5fdfbe4

Please sign in to comment.