Reputation: 567
How to convert from DOCX to DOCM ?
In this document there is a converting from docm to docx.
can we do the opposite ( DOCX to DOCM ) ?
Upvotes: 2
Views: 424
Reputation: 567
public void ConvertDOCXtoDOCM(string fileName)
{
bool fileChanged = false;
using (WordprocessingDocument document =
WordprocessingDocument.Open(fileName, true))
{
document.ChangeDocumentType(
WordprocessingDocumentType.MacroEnabledDocument);
// Track that the document has been changed.
fileChanged = true;
}
// If anything goes wrong in this file handling,
// the code will raise an exception back to the caller.
if (fileChanged)
{
// Create the new .docx filename.
var newFileName = Path.ChangeExtension(fileName, ".docm");
// If it already exists, it will be deleted!
if (File.Exists(newFileName))
{
File.Delete(newFileName);
}
// Rename the file.
File.Move(fileName, newFileName);
}
}
Upvotes: 1