Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the structure of a .docx and .doc file?

Tags:

docx

I have learned that .docx files are basically binary files. But I'm unaware of the structure that lies beneath.

What is the essential structure of a .docx file? Like, how long is the header? From what point does the actual document content start? Does it have any signature at the end?

Basically, what's the anatomy of a .docx file?

like image 741
DD25 Avatar asked Oct 14 '16 07:10

DD25


People also ask

How are DOCX files structured?

A Docx file comprises of a collection of XML files that are contained inside a ZIP archive. The contents of a new Word document can be viewed by unzipping its contents. The collection contains a list of XML files that are categorized as: MetaData Files - contains information about other files available in the archive.

What is the structure of a word document?

THL divides the Word document for essays into three general parts: front, body, and back. These sections are briefly described, immediately below, with instructions on how to apply Word styles for the structural elements of each section.

What is the DOCX format in word?

DOCX is a zipped, XML-based file format. Microsoft Word 2007 and later uses DOCX as the default file format when creating a new document. Support for loading and saving legacy DOC files is also included. DOC is the default format used with Office 97-2003.

What type of file does the .DOC or .DOCX extension indicate?

For example, the doc extension tells your computer that the file is a Microsoft Word file.


2 Answers

Docx is basically a zip archive with a lot of xml files in it. It is an open format and the documentation is available online. The wikipedia article has a general description and the links you will need.

like image 96
SingerOfTheFall Avatar answered Sep 20 '22 06:09

SingerOfTheFall


I am going to answer this question: "What's the Anatomy of a DocX File?"

Official Answer

Please see the official OOXML article, "Anatomy of OOXML," for an example DocX directory structure :

http://officeopenxml.com/anatomyofOOXML.php

For an example DocX XML document :

http://officeopenxml.com/WPsampleDoc.php

What I Personally Suggest

HOWEVER, after following these meticulously, and guessing where the details got foggy, I was unable to make the .docx file.

I chose this short cut : Make a Docx file in Libre Office (supports .docx extensions), make a generic template in the format of the docx files you expect to be generating, save the file as .docx, copy and save as .zip.

Open this .zip directory, and what you'll see I found to be much better at explaining the spec than the above, official links.

Example

For example, if you're making articles in .docx, you'd have [[Title]] at the top in title-casing/formatting, By: [[Author]], for author, etc., etc.. Then with your code, use that template, and just swap out the [[field]] for whatever $data you're ready to put into it.

like image 25
HoldOffHunger Avatar answered Sep 19 '22 06:09

HoldOffHunger