本文整理汇总了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);
}
示例2: Main
static void Main(string[] args)
{
Document doc = new Document("../../data/document.doc");
Document clone = doc.Clone();
clone.Save("AsposeClone.doc", SaveFormat.Doc);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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");
}
示例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
}
示例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);
}