public Stream CreateMappingForTemplate(Stream templateBytes, Stream mappingBytes, FillMappingInfo info)
        {
            var templateFields = OpenXmlWordProcessing.FindTemplateFields(templateBytes);
            var excelBytes     = OpenXmlSpreadsheet.FillMappingsSheet(mappingBytes, templateFields, info);

            return(excelBytes);
        }
示例#2
0
        public void CanGetTemplateFieldExpressions()
        {
            var bytes = new MemoryStream(Resources.open_xml_spreadsheet_tests001_xlsm);
            var info  = OpenXmlSpreadsheet.GetMappingInfo(bytes, null);

            Assert.NotEmpty(info.Expressions);
        }
 private MappingDetails TransformFull(MappingContent content)
 {
     if (content != null)
     {
         var info    = OpenXmlSpreadsheet.GetMappingInfo(content.Buffer, null);
         var mapping = new MappingDetails();
         Transform(content, mapping);
         mapping.Buffer      = content.Buffer;
         mapping.Expressions = info.Expressions;
         mapping.Sources     = info.Sources;
         return(mapping);
     }
     return(null);
 }
示例#4
0
        public void CanUseForwardOwnCellValues()
        {
            var bytes = new MemoryStream(Resources.use_forward_own_cell_values_xlsm);

            var info      = OpenXmlSpreadsheet.GetMappingInfo(bytes, null);
            var processor = new MappingExpressionEvaluator();
            var results   = processor.Evaluate(info.Expressions, info.Sources);

            Assert.True(results.All(r => r.Error == null));
            Assert.Equal("22", results.First(o => o.Name == "F01").Text);
            Assert.Equal("2", results.First(o => o.Name == "F02").Text);
            Assert.Equal("6", results.First(o => o.Name == "F03").Text);
            Assert.Equal("16", results.First(o => o.Name == "F04").Text);
            Assert.Equal("8", results.First(o => o.Name == "F05").Text);
        }
        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));
        }