public static byte[] GenerateDocument(byte[] templateBuffer, DCTWordDataObject dataobject) { byte[] buffer = templateBuffer; //File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templatePath)); using (MemoryStream ms = new MemoryStream()) { ms.Write(buffer, 0, buffer.Length); using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(ms, true)) { //var permList = wordDoc.MainDocumentPart.Document.Body.Descendants<PermStart>().ToList(); foreach (DCTDataProperty property in dataobject.PropertyCollection) { GeneralDataProcessor gdp = GeneralDataProcessor.CreateProcessor(wordDoc, property); gdp.Process(); } DeleteComments(wordDoc); if (wordDoc.MainDocumentPart.WordprocessingCommentsPart != null) { wordDoc.MainDocumentPart.WordprocessingCommentsPart.Comments.Save(); } wordDoc.MainDocumentPart.Document.Save(); } byte[] resultBuffer = new byte[(int)ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(resultBuffer, 0, (int)ms.Length); return(resultBuffer); } }
public static byte[] GenerateDocument(byte[] templateBuffer, DCTWordDataObject dataobject) { byte[] buffer = templateBuffer; using (MemoryStream ms = new MemoryStream()) { ms.Write(buffer, 0, buffer.Length); using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(ms, true)) { foreach (DCTDataProperty property in dataobject.PropertyCollection) { GeneralDataProcessor gdp = GeneralDataProcessor.CreateProcessor(wordDoc, property); gdp.Process(); } DeleteComments(wordDoc); if (wordDoc.MainDocumentPart.WordprocessingCommentsPart != null) { wordDoc.MainDocumentPart.WordprocessingCommentsPart.Comments.Save(); } wordDoc.MainDocumentPart.Document.Save(); } byte[] resultBuffer = new byte[(int)ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(resultBuffer, 0, (int)ms.Length); return(resultBuffer); } }