public string MailMerge([FromBody] ExportData exportData)
        {
            Byte[]       data   = Convert.FromBase64String(exportData.documentData.Split(',')[1]);
            MemoryStream stream = new MemoryStream();

            stream.Write(data, 0, data.Length);
            stream.Position = 0;
            try
            {
                Syncfusion.DocIO.DLS.WordDocument document = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);
                document.MailMerge.RemoveEmptyGroup      = true;
                document.MailMerge.RemoveEmptyParagraphs = true;
                document.MailMerge.ClearFields           = true;
                document.MailMerge.Execute(CustomerDataModel.GetAllRecords());
                document.Save(stream, Syncfusion.DocIO.FormatType.Docx);
            }
            catch (Exception)
            { }
            string sfdtText = "";

            Syncfusion.EJ2.DocumentEditor.WordDocument worddocument = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);
            sfdtText = Newtonsoft.Json.JsonConvert.SerializeObject(worddocument);
            worddocument.Dispose();
            return(sfdtText);
        }
示例#2
0
        public FileStreamResult Export(IFormCollection data)
        {
            if (data.Files.Count == 0)
            {
                return(null);
            }
            string fileName = this.GetValue(data, "filename");
            string name     = fileName;
            int    index    = name.LastIndexOf('.');
            string format   = index > -1 && index < name.Length - 1 ?
                              name.Substring(index) : ".doc";

            if (string.IsNullOrEmpty(name))
            {
                name = "Document1";
            }
            Stream    stream      = new MemoryStream();
            string    contentType = "";
            WDocument document    = this.GetDocument(data);

            if (format == ".pdf")
            {
                contentType = "application/pdf";
            }
            else
            {
                WFormatType type = GetWFormatType(format);
                switch (type)
                {
                case WFormatType.Rtf:
                    contentType = "application/rtf";
                    break;

                case WFormatType.WordML:
                    contentType = "application/xml";
                    break;

                case WFormatType.Dotx:
                    contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
                    break;

                case WFormatType.Doc:
                    contentType = "application/msword";
                    break;

                case WFormatType.Dot:
                    contentType = "application/msword";
                    break;
                }
                document.Save(stream, type);
            }
            document.Close();
            stream.Position = 0;
            return(new FileStreamResult(stream, contentType)
            {
                FileDownloadName = fileName
            });
        }
示例#3
0
        private WDocument GetDocument(IFormCollection data)
        {
            Stream    stream = new MemoryStream();
            IFormFile file   = data.Files[0];

            file.CopyTo(stream);
            stream.Position = 0;

            WDocument document = new WDocument(stream, WFormatType.Docx);

            stream.Dispose();
            return(document);
        }
示例#4
0
        internal WDocument GetDocument(IFormCollection data)
        {
            Stream stream = new MemoryStream();

            if (data.Files.Count == 0)
            {
                return(null);
            }
            IFormFile file = data.Files[0];

            file.CopyTo(stream);
            stream.Position = 0;

            WDocument document = new WDocument(stream, WFormatType.Docx);

            stream.Dispose();
            return(document);
        }