Word控件Spire.Doc 【文档操作】教程(十五):如何在 C# 中克隆一个 word 文档
使用 Spire.Doc,我们可以在 C#中将内容从一个 word 文档复制到另一个 word 文档中将内容从一个 word 文档复制到另一个 word 文档。中将内容从一个 word 文档复制到另一个 word 文档当我们需要从单个文档生成大量文档时,克隆文档会容易得多。clone方法加快了word文档的生成速度,开发者只需要一行代码就可以得到word文档的副本。
现在我们将展示如何在 C# 中克隆 word 文档的代码片段。
第 1 步:创建 Document 的新实例并从文件加载文档。
Document doc = new Document(); doc.LoadFromFile("Sample.docx",FileFormat.Docx2010);
第2步:克隆word文档。
doc.Clone();
第 3 步:将文档保存到文件中。
doc.SaveToFile("Cloneword.docx", FileFormat.Docx2010);
克隆word文档的有效截图:
克隆word文档的完整代码:
using Spire.Doc; namespace CloneWord { class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile("Sample.docx", FileFormat.Docx2010); doc.Clone(); doc.SaveToFile("Cloneword.docx", FileFormat.Docx2010); } } }
Word控件Spire.Doc 【文档操作】教程(十六):在 C# 中从 Word 文档中检测和删除 VBA 宏
使用 Spire.Doc,开发人员可以快速检测 Word 文档是否包含 VBA 宏,并从 Word 文档中删除所有 VBA 宏。本文将向您展示如何使用 Spire.Doc 从 Word 文档中检测和删除 VBA 宏的详细步骤。
详细步骤:
第 1 步:初始化 Document 对象并加载 Word 文档
Document document = new Document(); document.LoadFromFile("Input.docm");
第 2 步:如果文档包含宏,请将它们从文档中删除。
if (document.IsContainMacro) { document.ClearMacros(); }
第 3 步:保存文档。
document.SaveToFile("Output.docm", FileFormat.Docm);
完整代码:
using Spire.Doc; namespace Remove_Macros_from_Word { class Program { static void Main(string[] args) { //Initialize a Document object Document document = new Document(); //Load the Word document document.LoadFromFile("Input.docm"); //If the document contains macros, remove them from the document if (document.IsContainMacro) { document.ClearMacros(); } //Save the document document.SaveToFile("Output.docm", FileFormat.Docm); } } }