Пример #1
0
        private void AddRowWithReplacements(Table tbl, RollsheetPersonInfo m, int orgId)
        {
            var row = tbl.InsertRow(docx.Tables[0].Rows[0]);

            tbl.Rows.Add(row);
            var dict = replacements.DocXReplacementsDictionary(m.Person, orgId);

            foreach (var p in row.Paragraphs.Where(vv => vv.Text.HasValue()))
            {
                if (dict.Keys.Any(vv => p.Text.Contains(vv)))
                {
                    foreach (var d in dict)
                    {
                        if (p.Text.Contains(d.Key))
                        {
                            if (d.Key == "{barcodepeopleid}")
                            {
                                var s   = BarCodeStream(m.Person.PeopleId.ToString(), 40, showtext: false);
                                var img = curr.AddImage(s);
                                p.AppendPicture(img.CreatePicture());
                                p.ReplaceText(d.Key, "");
                            }
                            else if (d.Key.Equal("{MLG}"))
                            {
                                p.ReplaceText(d.Key, m.MemberTypeCode);
                            }
                            else if (d.Key.Equal("{highlight}"))
                            {
                                if (m.Highlight.HasValue())
                                {
                                    p.ReplaceText(d.Key, m.Highlight);
                                }
                                else
                                {
                                    p.Remove(false);
                                }
                            }
                            else if (d.Key.Equal("{altname}"))
                            {
                                p.ReplaceText(d.Key, m.UseAltName ? m.Person.AltName : "");
                            }
                            else if (d.Key.Equal("{name}"))
                            {
                                p.ReplaceText(d.Key, m.Person.Name2);
                                if (m.MemberTypeCode == "VS")
                                {
                                    row.Cells.Last().Shading = Color.FromArgb(226, 239, 217); // light green
                                }
                            }
                            else
                            {
                                p.ReplaceText(d.Key, d.Value);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void DoCellReplacements(Container cell, DirectoryInfo di)
        {
            var dict = replacements.DocXReplacementsDictionary(di.Person);

            foreach (var pg in cell.Paragraphs.Where(vv => vv.Text.HasValue()))
            {
                if (dict.Keys.Any(vv => pg.Text.Contains(vv)))
                {
                    foreach (var d in dict)
                    {
                        if (pg.Text.Contains(d.Key))
                        {
                            if (!ReplaceCode(pg, d.Key, di))
                            {
                                pg.ReplaceText(d.Key, d.Value);
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;

            var list = ExcelExportModel.DirectoryList(id);

            if (list.Count == 0)
            {
                response.Write("no data found");
                return;
            }
            var wc    = new WebClient();
            var bytes = wc.DownloadData(template);

            var ms = new MemoryStream(bytes);

            docx = DocX.Load(ms);

            replacements = new EmailReplacements(DbUtil.Db, docx);
            emptyReplacementsDictionary = replacements.DocXReplacementsDictionary(null);

            if (emptyReplacementsDictionary.ContainsKey("{lastnamestartswith}"))
            {
                BuildDocumentIndexStyle(list);
            }
            else
            {
                BuildDocument(list);
            }

            response.Clear();
            response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            response.AddHeader("content-disposition", $"attachment;filename={filename}-{DateTime.Now.ToSortableDateTime()}.docx");

            ms = new MemoryStream();
            docx.SaveAs(ms);
            ms.WriteTo(response.OutputStream);
            response.End();
        }