Ejemplo n.º 1
0
        private AssembleResult AsmDoc(string name, string data, string outName)
        {
            DirectoryInfo sourceDir    = new DirectoryInfo("../../../../test/templates/");
            FileInfo      templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
            FileInfo      dataXml      = new FileInfo(Path.Combine(sourceDir.FullName, data));
            DirectoryInfo destDir      = new DirectoryInfo("../../../../test/history/dot-net-results");
            FileInfo      outputDocx   = new FileInfo(Path.Combine(destDir.FullName, templateDocx.Name));
            string        templateName = outputDocx.FullName;
            string        resultName   = string.IsNullOrEmpty(outName) ? null : Path.Combine(destDir.FullName, outName);

            templateDocx.CopyTo(templateName, true);
            var            assembler = new OpenDocx.Assembler();
            AssembleResult assembleResult;

            using (var xmlData = new StreamReader(dataXml.FullName, System.Text.Encoding.UTF8)) {
                assembleResult = assembler.AssembleDocument(templateName, xmlData, resultName);
            }
            Assert.False(assembleResult.HasErrors);
            return(assembleResult);
        }
Ejemplo n.º 2
0
        public void XmlError()
        {
            string        name         = "xmlerror.docx";
            DirectoryInfo sourceDir    = new DirectoryInfo("../../../../test/templates/");
            FileInfo      templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
            FileInfo      dataXml      = new FileInfo(Path.Combine(sourceDir.FullName, "xmlerror.xml"));
            DirectoryInfo destDir      = new DirectoryInfo("../../../../test/history/dot-net-results");
            FileInfo      outputDocx   = new FileInfo(Path.Combine(destDir.FullName, name));
            string        templateName = outputDocx.FullName;
            string        resultName   = Path.Combine(destDir.FullName, "xmlerror-assembled.docx");

            templateDocx.CopyTo(templateName, true);
            var            assembler = new OpenDocx.Assembler();
            AssembleResult assembleResult;

            using (var xmlData = new StreamReader(dataXml.FullName, System.Text.Encoding.UTF8)) {
                assembleResult = assembler.AssembleDocument(templateName, xmlData, resultName);
            }
            Assert.True(File.Exists(assembleResult.Document));
        }