Reputation: 32635
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:
However, doing this for hundreds of files definitely ain't fun. =p
How would you automate this?
Upvotes: 15
Views: 24345
Reputation: 456
Hi you can do that using Spire.Doc library which is really good. You can install it easily through NuGet Package
PM> Install-Package Spire.Doc
To convert .doc to .docx
Document document = new Document();
//Load a Docx file
document.LoadFromFile(@"Sample.doc");
//Convert the Doc file to Docx
document.SaveToFile("ToDoc.docx", FileFormat.Docx);
To convert .docx to .doc
Document document = new Document();
//Load a Docx file
document.LoadFromFile(@"Sample.docx");
//Convert the Docx file to Doc
document.SaveToFile("ToDoc.doc", FileFormat.Doc);
Upvotes: 0
Reputation: 176
Install LibreOffice.
Use the command line tool:
soffice --convert-to docx *.doc
Upvotes: 2
Reputation: 280
If you're on macOS or Windows, it's as easy as installing the Python package doc2docx
and running the following commands:
pip install doc2docx
find "/path/to/doc/directory" -type f -name "*.doc" -exec doc2docx {} \;
Upvotes: 3
Reputation: 176169
There is no need to automate Word, which is rather slow and brittle due to pop-up messages, or to use Microsoft's Office File Converter (ofc.exe), which has an unnecessarily complicated user interface.
The simplest and fastest way would be to install either Office 2007 or download and install the Compatibility Pack from Microsoft (if not already done). Then you can convert from .doc to .docx easily using the following command:
"C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme <input file> <output file>
where <input file> and <output file> need to be fully qualified path names.
The command can be easily applied to multiple documents using for
:
for %F in (*.doc) do "C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme "%F" "%Fx"
Upvotes: 26
Reputation: 311536
The easiest way is to use the command-line Office File Converter. Just run
ofc
and the magic happens.
Upvotes: 7
Reputation: 6465
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
You can find plenty of example on google, just search for Word Automation in C# or something along that line.
Upvotes: 4