コード例 #1
0
 /// <summary>
 /// Find definitions in OpenXML(OPC) string
 /// </summary>
 /// <param name="openXml">OpenXML(OPC) string</param>
 public void TokenizeOpenXml(string openXml)
 {
     using (var wordDocument = WordprocessingDocument.FromFlatOpcString(openXml))
     {
         ProcessDocument(wordDocument);
     }
 }
コード例 #2
0
ファイル: WordTemplate.cs プロジェクト: wk-j/word-report
        public void Render(Stream stream, TemplateContext context, Dictionary <string, byte[]> imageDict = null)
        {
            var transformed = _template.Render(context);
            var doc         = WordprocessingDocument.FromFlatOpcString(transformed);

            if (imageDict != null)
            {
                doc.ReplaceImages(imageDict);
            }
            doc.Clone(stream);
        }
コード例 #3
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);
                    }
                }
        }
コード例 #4
0
        public void CanCreateFlatOpcWordprocessingDocuments()
        {
            using (var source = WordprocessingDocument.Open(Path.Combine(TestUtil.TestResultsDirectory, DocumentPath), true))
            {
                // Test FlatOpcDocument methods.
                // Check ToFlatOpcDocument() and FromFlatOpcDocument(XDocument).
                var flatOpcDoc = source.ToFlatOpcDocument();
                using (var dest = WordprocessingDocument.FromFlatOpcDocument(flatOpcDoc))
                    AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcDocument(XDocument, Stream, bool).
                using (Stream stream = new MemoryStream())
                    using (WordprocessingDocument.FromFlatOpcDocument(flatOpcDoc, stream, false))
                        using (var dest = WordprocessingDocument.Open(stream, false))
                            AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcDocument(XDocument, string, bool).
                using (WordprocessingDocument.FromFlatOpcDocument(flatOpcDoc, Path.Combine(TestUtil.TestResultsDirectory, DocumentClonePath), false))
                    using (var dest = WordprocessingDocument.Open(Path.Combine(TestUtil.TestResultsDirectory, DocumentClonePath), false))
                        AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcDocument(XDocument, Package).
                using (var stream = new MemoryStream())
                    using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                        using (var dest = WordprocessingDocument.FromFlatOpcDocument(flatOpcDoc, package))
                            AssertThatPackagesAreEqual(source, dest);

                // Test FlatOpcString methods.
                // Check ToFlatOpcString() and FromFlatOpcString(string).
                var flatOpcString = source.ToFlatOpcString();
                using (var dest = WordprocessingDocument.FromFlatOpcString(flatOpcString))
                    AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcString(string, Stream, bool).
                using (Stream stream = new MemoryStream())
                    using (WordprocessingDocument.FromFlatOpcString(flatOpcString, stream, false))
                        using (var dest = WordprocessingDocument.Open(stream, false))
                            AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcString(string, string, bool).
                using (WordprocessingDocument.FromFlatOpcString(flatOpcString, Path.Combine(TestUtil.TestResultsDirectory, DocumentClonePath), false))
                    using (var dest = WordprocessingDocument.Open(Path.Combine(TestUtil.TestResultsDirectory, DocumentClonePath), false))
                        AssertThatPackagesAreEqual(source, dest);

                // Check FromFlatOpcString(string, Package).
                using (var stream = new MemoryStream())
                    using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                        using (var dest = WordprocessingDocument.FromFlatOpcString(flatOpcString, package))
                            AssertThatPackagesAreEqual(source, dest);
            }
        }
コード例 #5
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);
                            }
                }
        }
コード例 #6
0
        /// <summary>
        /// Creates a new instance of DocumentType from a Flat OPC string.
        /// </summary>
        /// <param name="text">The Flat OPC string.</param>
        /// <typeparam name="TDocument">A subclass of <see cref="OpenXmlPackage" />.</typeparam>
        /// <returns>A new instance of DocumentType</returns>
        public static TDocument FromFlatOpcString <TDocument>(string text)
            where TDocument : OpenXmlPackage
        {
            var t = typeof(TDocument);

            if (t == typeof(WordprocessingDocument))
            {
                return(WordprocessingDocument.FromFlatOpcString(text) as TDocument);
            }
            if (t == typeof(SpreadsheetDocument))
            {
                return(SpreadsheetDocument.FromFlatOpcString(text) as TDocument);
            }
            if (t == typeof(PresentationDocument))
            {
                return(PresentationDocument.FromFlatOpcString(text) as TDocument);
            }
            throw new OpenXmlTransformationException("Unsupported document type: " + t);
        }