文檔半島外圍網上直營>>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交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線