예제 #1
0
        public async void FieldExtractorAsync(string name)
        {
            DirectoryInfo sourceDir    = new DirectoryInfo("../../../../test/templates/");
            FileInfo      templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
            DirectoryInfo destDir      = new DirectoryInfo("../../../../test/history/dot-net-results");
            FileInfo      outputDocx   = new FileInfo(Path.Combine(destDir.FullName, name));
            string        templateName = outputDocx.FullName;

            templateDocx.CopyTo(templateName, true);
            dynamic options = new ExpandoObject();

            options.templateFile           = templateName;
            options.removeCustomProperties = true;
            options.keepPropertyNames      = new object[] { "UpdateFields" };
            var od            = new OpenDocx.FieldExtractor();
            var extractResult = await od.ExtractFieldsAsync(options);

            Assert.True(File.Exists(extractResult.ExtractedFields));
            Assert.True(File.Exists(extractResult.TempTemplate));
        }
예제 #2
0
        public async void RemoveTaskPanes(string name)
        {
            DirectoryInfo sourceDir    = new DirectoryInfo("../../../../test/templates/");
            FileInfo      templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
            DirectoryInfo destDir      = new DirectoryInfo("../../../../test/history/dot-net-results");
            FileInfo      outputDocx   = new FileInfo(Path.Combine(destDir.FullName, name));
            string        templateName = outputDocx.FullName;

            templateDocx.CopyTo(templateName, true);
            dynamic options = new ExpandoObject();

            options.templateFile = templateName;
            var od            = new OpenDocx.FieldExtractor();
            var extractResult = await od.ExtractFieldsAsync(options);

            Assert.True(File.Exists(extractResult.TempTemplate));
            // ensure interim template (which SHOULD no longer have task panes) still validates
            var validator = new Validator();
            var result    = validator.ValidateDocument(extractResult.TempTemplate);

            Assert.False(result.HasErrors, result.ErrorList);
        }