当前位置: 首页>>代码示例>>C#>>正文


C# Document.Clone方法代码示例

本文整理汇总了C#中Document.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Clone方法的具体用法?C# Document.Clone怎么用?C# Document.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            // ExStart:ProduceMultipleDocuments            
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_MailMergeAndReporting();
            // Open the database connection.
            string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataDir + "Customers.mdb";
            OleDbConnection conn = new OleDbConnection(connString);
            conn.Open();
            // Get data from a database.
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM Customers", conn);
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataTable data = new DataTable();
            da.Fill(data);

            // Open the template document.
            Document doc = new Document(dataDir + "TestFile.doc");

            int counter = 1;
            // Loop though all records in the data source.
            foreach (DataRow row in data.Rows)
            {
                // Clone the template instead of loading it from disk (for speed).
                Document dstDoc = (Document)doc.Clone(true);

                // Execute mail merge.
                dstDoc.MailMerge.Execute(row);

                // Save the document.
                dstDoc.Save(string.Format(dataDir + "TestFile_out{0}.doc", counter++));
            }
            // ExEnd:ProduceMultipleDocuments
            Console.WriteLine("\nProduce multiple documents performed successfully.\nFile saved at " + dataDir);            
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:34,代码来源:ProduceMultipleDocuments.cs

示例2: Main

        static void Main(string[] args)
        {
            Document doc = new Document("../../data/document.doc");
            Document clone = doc.Clone();

            clone.Save("AsposeClone.doc", SaveFormat.Doc);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:7,代码来源:Program.cs

示例3: Run

        public static void Run()
        {
            // ExStart:ApplyCustomLogicToEmptyRegions
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_MailMergeAndReporting(); 

            string fileName = "TestFile.doc";
            // Open the document.
            Document doc = new Document(dataDir + fileName);

            // Create a data source which has some data missing.
            // This will result in some regions that are merged and some that remain after executing mail merge.
            DataSet data = GetDataSource();

            // Make sure that we have not set the removal of any unused regions as we will handle them manually.
            // We achieve this by removing the RemoveUnusedRegions flag from the cleanup options by using the AND and NOT bitwise operators.
            doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions & ~MailMergeCleanupOptions.RemoveUnusedRegions;

            // Execute mail merge. Some regions will be merged with data, others left unmerged.
            doc.MailMerge.ExecuteWithRegions(data);

            // The regions which contained data now would of been merged. Any regions which had no data and were
            // Not merged will still remain in the document.
            Document mergedDoc = doc.Clone(); // ExSkip
            // Apply logic to each unused region left in the document using the logic set out in the handler.
            // The handler class must implement the IFieldMergingCallback interface.
            ExecuteCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler());

            // Save the output document to disk.
            doc.Save(dataDir + "TestFile.CustomLogicEmptyRegions1_out.doc");
            
            // Reload the original merged document.
            doc = mergedDoc.Clone();

            // Apply different logic to unused regions this time.
            ExecuteCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler_MergeTable());

            doc.Save(dataDir + "TestFile.CustomLogicEmptyRegions2_out.doc");
            // ExEnd:ApplyCustomLogicToEmptyRegions
            // Reload the original merged document.
            doc = mergedDoc.Clone();
            // ExStart:ContactDetails 
            // Only handle the ContactDetails region in our handler.
            ArrayList regions = new ArrayList();
            regions.Add("ContactDetails");
            ExecuteCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler(), regions);
            // ExEnd:ContactDetails 
            dataDir = dataDir + "TestFile.CustomLogicEmptyRegions3_out.doc";
            doc.Save(dataDir );

            Console.WriteLine("\nMail merge performed successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:52,代码来源:ApplyCustomLogicToEmptyRegions.cs

示例4: Main

        static void Main(string[] args)
        {
            // Check for license and apply if exists
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
            if (File.Exists(licenseFile))
            {
                // Apply Aspose.Words API License
                Aspose.Words.License license = new Aspose.Words.License();
                // Place license file in Bin/Debug/ Folder
                license.SetLicense("Aspose.Words.lic");
            }

            Document doc = new Document("../../data/document.doc");
            Document clone = doc.Clone();

            clone.Save("AsposeClone.doc", SaveFormat.Doc);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:17,代码来源:Program.cs

示例5: Run

        public static void Run()
        {
            //ExStart:CloningDocument
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithDocument();

            // Load the document from disk.
            Document doc = new Document(dataDir + "TestFile.doc");

            Document clone = doc.Clone();

            dataDir = dataDir + "TestFile_clone_out_.doc";

            // Save the document to disk.
            clone.Save(dataDir);
            //ExEnd:CloningDocument
            Console.WriteLine("\nDocument cloned successfully.\nFile saved at " + dataDir);
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:18,代码来源:CloningDocument.cs

示例6: StreamIsDisposedCorrectlyAfterClone

        public void StreamIsDisposedCorrectlyAfterClone()
        {
            // Given
            Engine engine = new Engine();
            Pipeline pipeline = new Pipeline("Test", engine, Array.Empty<IModule>());
            DisposeCheckStream stream = new DisposeCheckStream();
            Document originalDoc = new Document(engine, pipeline, "Test", stream, null, Array.Empty<KeyValuePair<string, object>>(), true);
            Document clonedDoc = (Document)originalDoc.Clone(Array.Empty<KeyValuePair<string, object>>());

            // When
            originalDoc.Dispose();
            bool originalDocDisposedStream = stream.Disposed;
            clonedDoc.Dispose();
            bool clonedDocDisposedStream = stream.Disposed;

            // Then
            Assert.AreEqual(false, originalDocDisposedStream);
            Assert.AreEqual(true, clonedDocDisposedStream);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:19,代码来源:DocumentFixture.cs

示例7: ProduceMultipleDocuments

        public static void ProduceMultipleDocuments(string dataDir, string srcDoc)
        {
            // Open the database connection.
            string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataDir + "Customers.mdb";
            OleDbConnection conn = new OleDbConnection(connString);
            conn.Open();
            try
            {
                // Get data from a database.
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM Customers", conn);
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable data = new DataTable();
                da.Fill(data);

                // Open the template document.
                Document doc = new Document(dataDir + srcDoc);

                int counter = 1;
                // Loop though all records in the data source.
                foreach (DataRow row in data.Rows)
                {
                    // Clone the template instead of loading it from disk (for speed).
                    Document dstDoc = (Document)doc.Clone(true);

                    // Execute mail merge.
                    dstDoc.MailMerge.Execute(row);

                    // Save the document.
                    dstDoc.Save(string.Format(dataDir + "TestFile Out {0}.doc", counter++));
                }
            }
            finally
            {
                // Close the database.
                conn.Close();
            }
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:37,代码来源:Program.cs

示例8: Main

        public static void Main(string[] args)
        {
            // Sample infrastructure.
            string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
            string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;

            //ExStart
            //ExId:CustomHandleRegionsMain
            //ExSummary:Shows how to handle unmerged regions after mail merge with user defined code.
            // Open the document.
            Document doc = new Document(dataDir + "TestFile.doc");

            // Create a data source which has some data missing.
            // This will result in some regions that are merged and some that remain after executing mail merge.
            DataSet data = GetDataSource();

            // Make sure that we have not set the removal of any unused regions as we will handle them manually.
            // We achieve this by removing the RemoveUnusedRegions flag from the cleanup options by using the bitwise XOR operator.
            doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions ^ MailMergeCleanupOptions.RemoveUnusedRegions;

            // Execute mail merge. Some regions will be merged with data, others left unmerged.
            doc.MailMerge.ExecuteWithRegions(data);

            // The regions which contained data now would of been merged. Any regions which had no data and were
            // not merged will still remain in the document.
            Document mergedDoc = doc.Clone(); //ExSkip
            // Apply logic to each unused region left in the document using the logic set out in the handler.
            // The handler class must implement the IFieldMergingCallback interface.
            ExecuteCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler());

            // Save the output document to disk.
            doc.Save(dataDir + "TestFile.CustomLogicEmptyRegions1 Out.doc");
            //ExEnd

            // Reload the original merged document.
            doc = mergedDoc.Clone();

            // Apply different logic to unused regions this time.
            ExecuteCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler_MergeTable());

            doc.Save(dataDir + "TestFile.CustomLogicEmptyRegions2 Out.doc");

            // Reload the original merged document.
            doc = mergedDoc.Clone();

            //ExStart
            //ExId:HandleContactDetailsRegion
            //ExSummary:Shows how to specify only the ContactDetails region to be handled through the handler class.
            // Only handle the ContactDetails region in our handler.
            ArrayList regions = new ArrayList();
            regions.Add("ContactDetails");
            ExecuteCustomLogicOnEmptyRegions(doc, new EmptyRegionsHandler(), regions);
            //ExEnd

            doc.Save(dataDir + "TestFile.CustomLogicEmptyRegions3 Out.doc");
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:56,代码来源:Program.cs

示例9: CloneDocument

 public void CloneDocument()
 {
     //ExStart
     //ExFor:Document.Clone
     //ExId:CloneDocument
     //ExSummary:Shows how to deep clone a document.
     Document doc = new Document(MyDir + "Document.doc");
     Document clone = doc.Clone();
     //ExEnd
 }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:10,代码来源:ExDocument.cs

示例10: CloneTest

        public void CloneTest()
        {
            var xml = "<document xmlns=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><body a:b=\"2\" xmlns:a=\"http://a\"/></document>";
            var node = new Document(xml);
            var nod1 = node.Clone() as Document;

            Assert.Equal(node.ExtendedAttributes.Count(), nod1.ExtendedAttributes.Count());
            Assert.Equal(node.OuterXml, nod1.OuterXml);
            Assert.Equal(node.Body.OuterXml, nod1.Body.OuterXml);

        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:11,代码来源:OpenXmlElementTest.cs


注:本文中的Document.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。