文档半岛外围网上直营>>Aspose中文文档>>将 DOCM 转换为 DOCX
将 DOCM 转换为 DOCX
Aspose.Words是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
在Aspose.Words中,我们通常使用Aspose.Words API的Document构造函数来加载DOCM格式的文档,并使用 Document.Save方法将文档保存为DOCX。
使用 Aspose.Words以下代码示例展示了如何将 DOCM 转换为 DOCX:
Document doc = new Document("SourceDocument.docm");
doc.Save("ResultDocument.docx");
点击复制
需要使用的命名空间:
using System.IO; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using NUnit.Framework;
点击复制
以下代码示例通过验证文档是否包含 vbaProject 部分并删除该部分来修改指定的文档。代码删除该部分后,会在内部更改文档类型并重命名文档,以便使用 .docx 扩展名:
public void ConvertFromDocmToDocxFeature()
{
bool fileChanged = false;
using (WordprocessingDocument document =
WordprocessingDocument.Open(MyDir + "Convert from docm to docx.docm", true))
{
var docPart = document.MainDocumentPart;
// Look for the vbaProject part. If it is there, delete it.
var vbaPart = docPart.VbaProjectPart;
if (vbaPart != null)
{
// Delete the vbaProject part and then save the document.
docPart.DeletePart(vbaPart);
docPart.Document.Save();
// Change the document type to not macro-enabled.
document.ChangeDocumentType(
WordprocessingDocumentType.Document);
fileChanged = true;
}
}
// If anything goes wrong in this file handling,
// the code will raise an exception back to the caller.
if (fileChanged)
{
if (File.Exists(ArtifactsDir + "Convert from docm to docx - OpenXML.docm"))
File.Delete(ArtifactsDir + "Convert from docm to docx - OpenXML.docm");
File.Move(MyDir + "Convert from docm to docx.docm",
ArtifactsDir + "Convert from docm to docx - OpenXML.docm");
}
}
点击复制

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线