Automation: how to automate transforming .doc to .docx?

后端 未结 5 1984
庸人自扰
庸人自扰 2020-12-09 05:54

I have a bunch of .doc files in a folder which I need to convert to .docx.

To manually convert the .doc to .docx is pretty simple:

  1. Open .doc in Word 20
5条回答
  •  醉话见心
    2020-12-09 06:39

    Automate Word.

    If you are using .NET, add Microsoft.Office.Interop.Word (make sure it is version 12 - equivalent to Word 2007 so you can achieve the above) reference assembly to your project and use it it automate word app to do exactly what you want to do above. The pseudocode

    • Create the application object
    • Use the application object to open a document (by supplying it the file name)
    • Use the application object to perform SaveAs by supplying to it the format and output filename
    • Close the current document
    • Loop through the above till you finish with all documents
    • Housekeeping code to release the Word or Doc objects

    You can find plenty of example on google, just search for Word Automation in C# or something along that line.

提交回复
热议问题