繁体   English   中英

如何使用.Net-Core 将信息从(.docx 格式)传输到(.docm 格式)?

[英]how to transfer information from (.docx format) to (.docm format) using .Net-Core?

如何从 DOCX 转换为 DOCM?

在本文档中,有一个从docm 到docx 的转换。

https://docs.microsoft.com/en-us/office/open-xml/how-to-convert-a-word-processing-document-from-the-docm-to-the-docx-file-format

我们可以做相反的事情(DOCX 到 DOCM)吗?

    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);
        }

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM