public Stream CreateMappingForTemplate(Stream templateBytes, Stream mappingBytes, FillMappingInfo info) { var templateFields = OpenXmlWordProcessing.FindTemplateFields(templateBytes); var excelBytes = OpenXmlSpreadsheet.FillMappingsSheet(mappingBytes, templateFields, info); return(excelBytes); }
public EvaluationOutput Evaluate(EvaluationRequest request) { IEnumerable <TemplateField> templateFields = null; if (!string.IsNullOrEmpty(request.TemplateName)) { var template = repository.GetLatestTemplate(request.TemplateName); if (template != null) { templateFields = OpenXmlWordProcessing.FindTemplateFields(template.Buffer); } } if (templateFields == null) { templateFields = request.Expressions.Select(e => new TemplateField() { Name = e.Name, Parent = e.Parent, IsCollection = e.IsCollection, Content = e.Content }); } var processor = new MappingExpressionEvaluator(); var input = new EvaluationInput() { Fields = templateFields, Expressions = request.Expressions, Sources = request.Sources }; var response = processor.Evaluate(input); return(response); }
public void CanFindCorrectTemplateFieldsWhenAlternateContent() { var buffer = new MemoryStream(Resources.simple_receipt_template_docx); var templateFields = OpenXmlWordProcessing.FindTemplateFields(buffer); Assert.Equal(9, templateFields.Count()); }
public void CanFindTemplateFields002() { var buffer = new MemoryStream(Resources.find_template_fields002_docx); var templateFields = OpenXmlWordProcessing.FindTemplateFields(buffer); Assert.Equal(11, templateFields.Count()); }
public TemplateDetails GetTemplate(string templateName, string templateVersion = null) { var content = repository.GetTemplate(templateName, templateVersion); if (content == null) { return(null); } var fields = OpenXmlWordProcessing.FindTemplateFields(content.Buffer); var template = TransformFull(content, fields); return(template); }
public void CanCreateCorrectThemisDocument() { using var doc = WordprocessingDocument.Open(new MemoryStream(Resources.template_themis_docx), true); OpenXmlWordProcessing.SetContentControlContent(doc, "txt1", "SetContentControlContent"); OpenXmlWordProcessing.SetContentControlContent(doc, "txt2", "ProcessRepeatingSection"); OpenXmlWordProcessing.ProcessRepeatingSection(doc, "TablePercentage", new Dictionary <string, IEnumerable <string> >() { { "MnthOrd", new List <string> { "1os", "2os", "3os" } }, { "Prcntge", new List <string> { "10%", "20%", "30%" } }, }); doc.SaveAs(@".\__document_themis.docx"); }
public void CanFindTemplateFields001() { var buffer = new MemoryStream(Resources.find_template_fields001_docx); var templateFields = OpenXmlWordProcessing.FindTemplateFields(buffer); Assert.Equal(7, templateFields.Count()); Assert.Equal(new string[] { "FromAccountNumber", "FromAccountHolder", "ToAccountNumber", "Currency", "Amount", "TransactionDate", "TransactionTime" }, templateFields.Select(o => o.Name).ToArray()); }
public void CanEvaluateForExcelExample01() { var json = JObject.Parse(Resources.evaluate_for_excel_example01_json); var request = json.ToObject <EvaluationRequest>(); var templateBytes = new MemoryStream(Resources.evaluate_for_excel_example01_docx); var templateFields = OpenXmlWordProcessing.FindTemplateFields(templateBytes); var processor = new MappingExpressionEvaluator(CultureInfo.GetCultureInfo("el-GR")); var input = new EvaluationInput() { Fields = templateFields, Expressions = request.Expressions, Sources = request.Sources }; var response = processor.Evaluate(input); var fields = new Dictionary <string, string>(); response.Results.ToList().ForEach(o => fields.Add(o.Name, o.Text)); Assert.Equal(23, response.Total); Assert.Equal(0, response.Errors); Assert.Equal(DateTime.Today.ToString("d/M/yyyy"), fields["F01"]); Assert.Equal("ΠΡΟΘΕΣΜΙΑΚΗ ΜΕ BONUS 3 ΜΗΝΩΝ - ΑΠΟ ΕΥΡΩ 10.000", fields["F02"]); Assert.Equal("923456789012345", fields["F03"]); Assert.Equal("3", fields["F04"]); Assert.Equal("MONTH", fields["F05"]); Assert.Equal("έκαστης", fields["F06"]); Assert.Equal("10000", fields["F07"]); Assert.Equal("3", fields["F08"]); Assert.Equal("1", fields["F09"]); Assert.Equal("['{}','{}']", fields["F10"]); Assert.Equal("['1','3']", fields["F11"]); Assert.Equal("['0,2','0,25']", fields["F12"]); Assert.Equal("['500','1000']", fields["F13"]); Assert.Equal("0,17", fields["F14"]); Assert.Equal("1", fields["F15"]); Assert.Equal("Πρώτος προαιρετικός όρος", fields["F16"]); Assert.Equal("1", fields["F17"]); Assert.Equal("", fields["F18"]); Assert.Equal("5000", fields["F19"]); Assert.Equal("10000", fields["F20"]); Assert.Equal("Προθεσμιακή με Bonus 3 Μηνών - Από Ευρώ 10.000", fields["F21"]); Assert.Equal("923456789012345", fields["F22"]); Assert.Equal("123", fields["F23"]); }
public Stream CreateDocument(Stream templateBytes, Stream mappingBytes, DocumentPayload payload) { var templateFields = OpenXmlWordProcessing.FindTemplateFields(templateBytes); MappingInfo mappingInfo; if (mappingBytes != null) { mappingInfo = OpenXmlSpreadsheet.GetMappingInfo(mappingBytes, payload.Sources); } else { mappingInfo = OpenXmlSpreadsheet.BuildIdentityExpressions(templateFields, payload.Sources); } var results = CreateDocumentInternal(templateFields, mappingInfo.Expressions, mappingInfo.Sources); var contentControlData = BuildContentControlData(templateFields, results); return(OpenXmlWordProcessing.MergeTemplateWithMappings(contentControlData, templateBytes)); }
public async Task <TemplateDetails> CreateTemplate(TemplateData templateData, Stream bytes) { templateData = templateData ?? throw new ArgumentNullException(nameof(templateData)); var templateName = templateData.TemplateName ?? throw new ArgumentNullException(nameof(templateData.TemplateName)); IEnumerable <TemplateField> fields; try { fields = OpenXmlWordProcessing.FindTemplateFields(bytes); } catch (FileFormatException) { throw new ArgumentException(nameof(bytes)); } var content = await repository.CreateTemplate(templateName, bytes); if (htmlRepository != null) { var conversion = OpenXmlWordConverter.ConvertToHtml(bytes, content.Name); htmlRepository.SaveHtml(content.Name, null, conversion.Images); } return(TransformFull(content, fields)); }