Exemplo n.º 1
0
 public void CanDoFileBasedCloneSpreadsheet()
 {
     using (var tempFile = TemporaryFile.Create())
         using (var stream = GetStream(TestFiles.Spreadsheet))
             using (var source = SpreadsheetDocument.Open(stream, false))
                 using (source.Clone(tempFile.Path, false))
                     using (var dest = SpreadsheetDocument.Open(tempFile.Path, false))
                     {
                         PackageAssert.Equal(source, dest);
                     }
 }
Exemplo n.º 2
0
 public void CanDoFileBasedClonePresentation()
 {
     using (var tempFile = TemporaryFile.Create())
         using (var stream = GetStream(TestFiles.Presentation))
             using (var source = PresentationDocument.Open(stream, false))
                 using (source.Clone(tempFile.Path, false))
                     using (var dest = PresentationDocument.Open(tempFile.Path, false))
                     {
                         PackageAssert.Equal(source, dest);
                     }
 }
Exemplo n.º 3
0
 public void CanCreateFlatOpcPresentationDocuments()
 {
     using (var inputStream = GetStream(TestFiles.Presentation))
         using (var source = PresentationDocument.Open(inputStream, false))
         {
             var flatOpcDoc = source.ToFlatOpcDocument();
             using (var dest = PresentationDocument.FromFlatOpcDocument(flatOpcDoc))
             {
                 PackageAssert.Equal(source, dest);
             }
         }
 }
Exemplo n.º 4
0
        public void CanCreateFlatOpcWordprocessingDocuments5()
        {
            using (var inputStream = GetStream(TestFiles.Document))
                using (var source = WordprocessingDocument.Open(inputStream, false))
                {
                    var flatOpcString = source.ToFlatOpcString();

                    using (var dest = WordprocessingDocument.FromFlatOpcString(flatOpcString))
                    {
                        PackageAssert.Equal(source, dest);
                    }
                }
        }
Exemplo n.º 5
0
        public void CanCreateFlatOpcSpreadsheetDocuments1()
        {
            using (var inputStream = GetStream(TestFiles.Spreadsheet))
                using (var source = SpreadsheetDocument.Open(inputStream, false))
                {
                    var flatOpcDoc = source.ToFlatOpcDocument();

                    using (var dest = SpreadsheetDocument.FromFlatOpcDocument(flatOpcDoc))
                    {
                        PackageAssert.Equal(source, dest);
                    }
                }
        }
        public void CanCreateFlatOpcDocuments5()
        {
            using (var inputStream = GetStream(Path))
                using (var source = Open(inputStream, false))
                {
                    var flatOpcString = source.ToFlatOpcString();

                    using (var dest = FromFlatOpcString(flatOpcString))
                    {
                        PackageAssert.Equal(source, dest);
                    }
                }
        }
Exemplo n.º 7
0
        public void CanCreateFlatOpcWordprocessingDocuments3()
        {
            using (var inputStream = GetStream(TestFiles.Document))
                using (var source = WordprocessingDocument.Open(inputStream, false))
                {
                    var flatOpcDoc = source.ToFlatOpcDocument();

                    using (var tempFile = TemporaryFile.Create())
                        using (WordprocessingDocument.FromFlatOpcDocument(flatOpcDoc, tempFile.Path, false))
                            using (var dest = WordprocessingDocument.Open(tempFile.Path, false))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                }
        }
Exemplo n.º 8
0
        public void CanCreateFlatOpcWordprocessingDocuments2()
        {
            using (var inputStream = GetStream(TestFiles.Document))
                using (var source = WordprocessingDocument.Open(inputStream, false))
                {
                    var flatOpcDoc = source.ToFlatOpcDocument();

                    using (Stream stream = new MemoryStream())
                        using (WordprocessingDocument.FromFlatOpcDocument(flatOpcDoc, stream, false))
                            using (var dest = WordprocessingDocument.Open(stream, false))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                }
        }
Exemplo n.º 9
0
        public void CanCreateFlatOpcSpreadsheetDocuments7()
        {
            using (var inputStream = GetStream(TestFiles.Spreadsheet))
                using (var source = SpreadsheetDocument.Open(inputStream, false))
                {
                    var flatOpcString = source.ToFlatOpcString();

                    using (var tempFile = TemporaryFile.Create())
                        using (SpreadsheetDocument.FromFlatOpcString(flatOpcString, tempFile.Path, false))
                            using (var dest = SpreadsheetDocument.Open(tempFile.Path, false))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                }
        }
Exemplo n.º 10
0
        public void CanCreateFlatOpcSpreadsheetDocuments4()
        {
            using (var inputStream = GetStream(TestFiles.Spreadsheet))
                using (var source = SpreadsheetDocument.Open(inputStream, false))
                    using (var stream = new MemoryStream())
                        using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                        {
                            var flatOpcDoc = source.ToFlatOpcDocument();

                            using (var dest = SpreadsheetDocument.FromFlatOpcDocument(flatOpcDoc, package))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                        }
        }
        public void CanCreateFlatOpcDocuments2()
        {
            using (var inputStream = GetStream(Path))
                using (var source = Open(inputStream, false))
                {
                    var flatOpcDoc = source.ToFlatOpcDocument();

                    using (var stream = new MemoryStream())
                        using (FromFlatOpcDocument(flatOpcDoc, stream, false))
                            using (var dest = Open(stream, false))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                }
        }
Exemplo n.º 12
0
        public void CanCreateFlatOpcPresentationDocuments6()
        {
            using (var inputStream = GetStream(TestFiles.Presentation))
                using (var source = PresentationDocument.Open(inputStream, false))
                {
                    var flatOpcString = source.ToFlatOpcString();

                    using (Stream stream = new MemoryStream())
                        using (PresentationDocument.FromFlatOpcString(flatOpcString, stream, false))
                            using (var dest = PresentationDocument.Open(stream, false))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                }
        }
Exemplo n.º 13
0
        public void CanCreateFlatOpcWordprocessingDocuments8()
        {
            using (var inputStream = GetStream(TestFiles.Document))
                using (var source = WordprocessingDocument.Open(inputStream, false))
                {
                    var flatOpcString = source.ToFlatOpcString();

                    using (var stream = new MemoryStream())
                        using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                            using (var dest = WordprocessingDocument.FromFlatOpcString(flatOpcString, package))
                            {
                                PackageAssert.Equal(source, dest);
                            }
                }
        }
Exemplo n.º 14
0
        public void CanSaveAsPowerpoint()
        {
            using (var stream = GetStream(TestFiles.Presentation))
                using (var source = PresentationDocument.Open(stream, false))
                    using (var tempFile = TemporaryFile.Create())
                    {
                        using (source.SaveAs(tempFile.Path))
                        {
                        }

                        using (var dest = PresentationDocument.Open(tempFile.Path, false))
                        {
                            PackageAssert.Equal(source, dest);
                        }
                    }
        }
        public void CanCreateFlatOpcDocumentsDynamically()
        {
            using (var stream = new MemoryStream())
                using (var document = Create(stream))
                {
                    AddMainPart(document);

                    document.Save();

                    string opc = document.ToFlatOpcString();
                    using (var dest = FromFlatOpcString(opc))
                    {
                        PackageAssert.Equal(document, dest);
                    }
                }
        }
Exemplo n.º 16
0
        public void CanSaveAsExcel()
        {
            using (var tempFile = TemporaryFile.Create())
                using (var stream = GetStream(TestFiles.Spreadsheet))
                    using (var source = SpreadsheetDocument.Open(stream, false))
                    {
                        using (source.SaveAs(tempFile.Path))
                        {
                        }

                        using (var dest = SpreadsheetDocument.Open(tempFile.Path, false))
                        {
                            PackageAssert.Equal(source, dest);
                        }
                    }
        }
Exemplo n.º 17
0
        public void CanSaveAsWord()
        {
            using (var tempFile = TemporaryFile.Create())
                using (var stream = GetStream(TestFiles.Document))
                    using (var source = WordprocessingDocument.Open(stream, false))
                    {
                        using (source.SaveAs(tempFile.Path))
                        {
                        }

                        using (var dest = WordprocessingDocument.Open(tempFile.Path, false))
                        {
                            PackageAssert.Equal(source, dest);
                        }
                    }
        }
Exemplo n.º 18
0
        public void CanDoStreamBasedCloningPowerpoint()
        {
            using (var stream = GetStream(TestFiles.Presentation))
                using (var source = PresentationDocument.Open(stream, false))
                    using (var memoryStream = new MemoryStream())
                    {
                        using (source.Clone(memoryStream, false))
                        {
                        }

                        memoryStream.Position = 0;

                        using (var dest = PresentationDocument.Open(memoryStream, false))
                        {
                            PackageAssert.Equal(source, dest);
                        }
                    }
        }
Exemplo n.º 19
0
        public void CanDoStreamBasedCloningExcel()
        {
            using (var stream = GetStream(TestFiles.Spreadsheet))
                using (var source = SpreadsheetDocument.Open(stream, false))
                    using (var memoryStream = new MemoryStream())
                    {
                        using (source.Clone(memoryStream, true))
                        {
                        }

                        memoryStream.Position = 0;

                        using (var dest = SpreadsheetDocument.Open(memoryStream, false))
                        {
                            PackageAssert.Equal(source, dest);
                        }
                    }
        }
Exemplo n.º 20
0
        public void CanDoStreamBasedCloningWord()
        {
            using (var stream = GetStream(TestFiles.Document))
                using (var source = WordprocessingDocument.Open(stream, false))
                    using (var memoryStream = new MemoryStream())
                    {
                        using (source.Clone(memoryStream, true))
                        {
                        }

                        memoryStream.Position = 0;

                        using (var dest = WordprocessingDocument.Open(memoryStream, false))
                        {
                            PackageAssert.Equal(source, dest);
                        }
                    }
        }
Exemplo n.º 21
0
        public void CanDoPackageBasedCloningPowerpoint()
        {
            using (var stream = GetStream(TestFiles.Presentation, true))
                using (var source = PresentationDocument.Open(stream, true))
                    using (var ms = new MemoryStream())
                    {
                        using (var package = Package.Open(ms, FileMode.Create))
                        {
                            source.Clone(package).Close();
                        }

                        ms.Position = 0;

                        using (var destination = PresentationDocument.Open(ms, true))
                        {
                            PackageAssert.Equal(source, destination);
                        }
                    }
        }
Exemplo n.º 22
0
        public void CanCloneDocument()
        {
            using (var file = TemporaryFile.Create())
            {
                using (var stream = GetStream(TestFiles.Document))
                    using (var source = WordprocessingDocument.Open(stream, false))
                        using (var clone = (WordprocessingDocument)source.Clone())
                        {
                            var body = clone.MainDocumentPart.Document.Body;
                            body.InsertBefore(new Paragraph(new Run(new Text("Hello World"))), body.FirstChild);
                            clone.SaveAs(file.Path).Close();

                            using (var dest = WordprocessingDocument.Open(file.Path, false))
                            {
                                // We want the documents to be different.
                                Assert.Throws <Xunit.Sdk.EqualException>(() => PackageAssert.Equal(source, dest));
                            }
                        }
            }
        }
        public void CanCreateFlatOpcDocumentsDynamically()
        {
            using (var stream = new MemoryStream())
                using (var document = Create(stream))
                {
                    AddMainPart(document);

                    document.Save();

                    if (OpenXmlPackage.CanSave)
                    {
                        string opc = document.ToFlatOpcString();
                        using (var dest = FromFlatOpcString(opc))
                        {
                            PackageAssert.Equal(document, dest);
                        }
                    }
                    else
                    {
                        Assert.Throws <IOException>(() => document.ToFlatOpcString());
                    }
                }
        }