Exemplo n.º 1
0
        public void WriteExtraAttr()
        {
            string file = System.IO.Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".docx");

            CopyFileStream(TestFileStreams.HelloO14, file);

            //open it using the sdk
            using (var doc = WordprocessingDocument.Open(file, true))
            {
                // Touch the font table part.
                var fontTablePart = doc.MainDocumentPart.GetPartsOfType <FontTablePart>().First();
                var root          = fontTablePart.Fonts;

                var docNode = doc.MainDocumentPart.Document;
            }


            //open it again, mark sure in font part, the "w14" prefix is still recognized
            using (WordprocessingDocument testDocument = WordprocessingDocument.Open(file, true))
            {
                OpenXmlPart target = testDocument.MainDocumentPart.FontTablePart;
                using (Stream stream = target.GetStream())
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream))
                    {
                        reader.Read();
                        reader.MoveToContent();

                        var ns = reader.LookupNamespace("w14");
                        Assert.NotEqual(null, ns);
                    }
            }
            System.IO.File.Delete(file);
        }