Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading .docx in C++

I'm trying to create a program that reads a .docx file and posts it content to a blog/forum for personal use. I finally have figured out how to use libcurl to do (what I figured) was the harder part of the program. Now I just have to read the .docx file, but have come under a snag. I can't seem to find any documentation on how to do this. Any ideas?

like image 766
mcFreid Avatar asked Mar 01 '23 12:03

mcFreid


2 Answers

The easiest way is to use Word to do this. It has limitations on licensing.

The SO question Creating, opening and printing a word file from C++ has some good references.

Edit:

According to these questions/answers can unzip the Open XML file and process the XML file directly:

  • How can I read a Word 2007 .docx file?

If you use .NET there are more (C#) questions to read:

  • How to grab text from word (docx) document in C#?
  • How to load MS Word document in C# (.NET)?
  • How can I programatically use C# to append multiple DOCX files together?
like image 121
Peter Olsson Avatar answered Mar 03 '23 03:03

Peter Olsson


If you want to stay on the open-source world, OpenOffice 3 should be able to process .docx files. There is a project to implement an API for many languages, I don't really know how complete or complex it is.

There is a script in PHP that can convert from .docx into plain text. That is, if you are not scared that all docs are in russian). That could be another option (triggering the php script with a system call and parsing the results from a file)

like image 45
David Rodríguez - dribeas Avatar answered Mar 03 '23 02:03

David Rodríguez - dribeas