Example #1
0
        public void LoadIgnorable()
        {
            string file = System.IO.Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".docx");

            CopyFileStream(TestFileStreams.mcdoc, file);

            OpenXmlElement p1       = null;
            OpenSettings   settings = new OpenSettings();

            settings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessLoadedPartsOnly, FileFormatVersions.Office2007);
            using (WordprocessingDocument testDocument = WordprocessingDocument.Open(file, true, settings))
            {
                OpenXmlPart            target = testDocument.MainDocumentPart;
                OpenXmlPartRootElement root   = target.RootElement;

                p1 = root.FirstChild.FirstChild;
                root.Save();
            }
            //should throw exception
            Assert.Throws <KeyNotFoundException>(() =>
            {
                p1.GetAttribute("editId", "http://schemas.microsoft.com/office/word/2008/9/12/wordml");
            });
            System.IO.File.Delete(file);
        }
Example #2
0
        public void LoadIgnorable()
        {
            string file = "mcdoc.docx";

            CopyFileStream(TestFileStreams.mcdoc, file);

            //using (WordprocessingDocument testDocument = WordprocessingDocument.Open(file, false, DocumentFormat.OpenXml.MCMode.Full, false))
            //using (WordprocessingDocument testDocument = WordprocessingDocument.Open(file, false))
            //{
            //    OpenXmlPart target = testDocument.MainDocumentPart;
            //    OpenXmlPartRootElement root = target.RootElement;
            //    OpenXmlElement p = root.FirstChild.FirstChild;
            //    var attr = p.GetAttribute("editId", "http://schemas.microsoft.com/office/word/2008/9/12/wordml");
            //    Assert.Equal("w14", attr.Prefix);
            //}

            OpenXmlElement p1       = null;
            OpenSettings   settings = new OpenSettings();

            settings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessLoadedPartsOnly, FileFormatVersions.Office2007);
            using (WordprocessingDocument testDocument = WordprocessingDocument.Open(file, true, settings))
            {
                OpenXmlPart            target = testDocument.MainDocumentPart;
                OpenXmlPartRootElement root   = target.RootElement;

                p1 = root.FirstChild.FirstChild;
                root.Save();
            }
            //should throw exception
            Assert.Throws <KeyNotFoundException>(() =>
            {
                p1.GetAttribute("editId", "http://schemas.microsoft.com/office/word/2008/9/12/wordml");
            });
            System.IO.File.Delete(file);
        }
Example #3
0
        public void LoadACB2()
        {
            string file = System.IO.Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".docx");

            CopyFileStream(TestFileStreams.mcppt, file);
            OpenSettings settings = new OpenSettings();

            settings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessLoadedPartsOnly, FileFormatVersions.Office2007);
            using (PresentationDocument doc = PresentationDocument.Open(file, true, settings))
            {
                OpenXmlPart            target = doc.PresentationPart.TableStylesPart;
                OpenXmlPartRootElement root   = target.RootElement;

                var ele = root.FirstChild;
                Assert.True(ele is DocumentFormat.OpenXml.Drawing.TableStyleEntry);
                var attr = ele.GetAttribute("myattr", "http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing");
                Assert.Equal("1", attr.Value);
                Assert.True(ele is DocumentFormat.OpenXml.Drawing.TableStyleEntry);

                ele  = ele.NextSibling();
                attr = ele.GetAttribute("myattr", "http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing");
                Assert.Equal("2", attr.Value);
                Assert.True(ele is DocumentFormat.OpenXml.Drawing.TableStyleEntry);

                ele  = ele.NextSibling();
                attr = ele.GetAttribute("myattr", "http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing");
                Assert.Equal("3", attr.Value);
                Assert.True(ele is DocumentFormat.OpenXml.Drawing.TableStyleEntry);

                ele  = ele.NextSibling();
                attr = ele.GetAttribute("myattr", "http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing");
                Assert.Equal("4", attr.Value);
                Assert.True(ele is DocumentFormat.OpenXml.Drawing.TableStyleEntry);

                ele = ele.NextSibling();
                Assert.Equal(null, ele);

                root.Save();
            }
            System.IO.File.Delete(file);
        }
Example #4
0
        public void LoadACB()
        {
            var settings = new OpenSettings
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessLoadedPartsOnly, FileFormatVersions.Office2007),
            };

            using (var stream = GetStream(TestFiles.Mcdoc, true))
                using (var testDocument = WordprocessingDocument.Open(stream, true, settings))
                {
                    OpenXmlPart            target = testDocument.MainDocumentPart;
                    OpenXmlPartRootElement root   = target.RootElement;

                    var run       = root.FirstChild.FirstChild.FirstChild.NextSibling();
                    var secondele = run.FirstChild.NextSibling();

                    root.Save();

                    Assert.IsType <Picture>(secondele);
                }
        }
Example #5
0
        public void ParseDocxPart(OpenXmlPartRootElement doc, ExecuteArgs param)
        {
            var list = new List <Word.SdtElement>();

            Find <Word.SdtElement>(doc, list);
            foreach (var item in list)
            {
                OpenXmlElement stdContent = FindChildByName(item, "sdtContent");
                var            element    = stdContent.FirstChild;
                var            prop       = item.Descendants <Word.SdtProperties>().FirstOrDefault();
                var            temp       = prop.Descendants <Word.TemporarySdt>().FirstOrDefault();
                var            tag        = prop.Descendants <Word.Tag>().FirstOrDefault();
                if (tag == null)
                {
                    tag = stdContent.Descendants <Word.Tag>().FirstOrDefault();
                }

                if (tag != null)
                {
                    object val = ParseString(param, tag.Val.ToString());
                    if (val != null)
                    {
                        if (temp != null)
                        {
                            element.Remove();
                            item.Parent.ReplaceChild(element, item);
                        }
                        if (val is QResult)
                        {
                            FillTable(item, (QResult)val);
                        }
                        else
                        {
                            ReplaceString(element, val.ToString());
                        }
                    }
                }
            }
            doc.Save();
        }
Example #6
0
        public void LoadACB()
        {
            string file = System.IO.Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".docx");

            CopyFileStream(TestFileStreams.mcdoc, file);

            OpenSettings settings = new OpenSettings();

            settings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessLoadedPartsOnly, FileFormatVersions.Office2007);
            using (WordprocessingDocument testDocument = WordprocessingDocument.Open(file, true, settings))
            {
                OpenXmlPart            target = testDocument.MainDocumentPart;
                OpenXmlPartRootElement root   = target.RootElement;

                var run       = root.FirstChild.FirstChild.FirstChild.NextSibling();
                var secondele = run.FirstChild.NextSibling();

                root.Save();

                Assert.True(secondele is DocumentFormat.OpenXml.Wordprocessing.Picture);
            }
            System.IO.File.Delete(file);
        }