What folder can I put my data in in a DOCX/PPTX/XLSX file?

J

Ji Zhou [MSFT]

Hello Dave,

Good morning! This is Ji Zhou [MSFT] and I will be working on this issue
with you.

Firstly I want to ensure I understand this issue correctly. We are trying
to insert a custom data file into the Office Open XML file docx/pptx/xlsx.
But after we save the Office Open XML file, the custom data file we
inserted is lost. Please correct me if my understanding is not accurate.

Based on my research on this issue, before we can add the custom data file
into Office Open XML file, we need to declare the file's extension in the
[Content_Types].xml file. For example, if we want to add a .txt file in the
DOCX file. We need to insert the following line into the
[Content_Types].xml file:
<Default Extension="txt" ContentType="text/plain" />

The reason is that no matter in which folder we put our custom data file,
if Word cannot recognize the file, it will consider the document is
corrupted and delete that custom data file during the recovering process.
And Word recognizes the file type by reading the content of
[Content_Types].xml file. By default, its content looks like:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Types
xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels"
ContentType="application/vnd.openxmlformats-package.relationships+xml" />
<Default Extension="xml" ContentType="application/xml" />
<Override PartName="/word/document.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.
document.main+xml" />
<Override PartName="/word/styles.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.
styles+xml" />
<Override PartName="/docProps/app.xml"
ContentType="application/vnd.openxmlformats-officedocument.extended-properti
es+xml" />
<Override PartName="/word/settings.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.
settings+xml" />
<Override PartName="/word/theme/theme1.xml"
ContentType="application/vnd.openxmlformats-officedocument.theme+xml" />
<Override PartName="/word/fontTable.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.
fontTable+xml" />
<Override PartName="/word/webSettings.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.
webSettings+xml" />
<Override PartName="/docProps/core.xml"
ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
</Types>

Without modifying the [Content_Types].xml, if I add a .txt file into the
Word subfolder and open the document, I receive the error says that "The
Office Open XML file test.docx cannot be opened because there are problems
with the contents". After I recovery the document and save it. My added
.txt file is discarded by Word. But, if I add the above line, the .txt file
I added will not be discarded any more.

Hope this helps! If you have any future concerns about this, please let me
know. I will do my best to have some more researches.


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

I am adding an xml file - data/order.xml and the [Content_Types].xml
file is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types
xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels"
ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
....

but it is still removing it. What else do I need to do?

thanks - dave


Hello Dave,

Good morning! This is Ji Zhou [MSFT] and I will be working on this issue
with you.

Firstly I want to ensure I understand this issue correctly. We are trying
to insert a custom data file into the Office Open XML file docx/pptx/xlsx.
But after we save the Office Open XML file, the custom data file we
inserted is lost. Please correct me if my understanding is not accurate.

Based on my research on this issue, before we can add the custom data file
into Office Open XML file, we need to declare the file's extension in the
[Content_Types].xml file. For example, if we want to add a .txt file in the
DOCX file. We need to insert the following line into the
[Content_Types].xml file:
<Default Extension="txt" ContentType="text/plain" />

The reason is that no matter in which folder we put our custom data file,
if Word cannot recognize the file, it will consider the document is
corrupted and delete that custom data file during the recovering process.
And Word recognizes the file type by reading the content of
[Content_Types].xml file. By default, its content looks like:

...

Without modifying the [Content_Types].xml, if I add a .txt file into the
Word subfolder and open the document, I receive the error says that "The
Office Open XML file test.docx cannot be opened because there are problems
with the contents". After I recovery the document and save it. My added
txt file is discarded by Word. But, if I add the above line, the .txt file
I added will not be discarded any more.

Hope this helps! If you have any future concerns about this, please let me
know. I will do my best to have some more researches.


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Ji Zhou [MSFT]

Hello Dave,

I am sorry about that I make a mistake in my last reply. Indeed, adding the
extension definition only makes Word do not consider the document as
corrupted. But, the custom file will still be removed from the Word
document.

To add a custom file into the zipped document anywhere, we need to define
the custom file's relationship in the file word\_rels\document.xml.rels. I
achieve that with the following steps:

1.Create a word 2007 file named sample.docx. Open it, type some text and
save it.

2.Change sample.docx name to sample.zip and extract the zip file to the
local driver.

3.Create the data folder and create the custom file order.xml in the new
created folder.

4.Open and edit the file word\_rels\document.xml.rels. Add the following
relationship before the </relationships> mark and save it.
<Relationship Id="myCustomXmlRelationship"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/cu
stomXml" Target="../data/order.xml" />

5.Zip and change the file name back to sample.docx. Open it in Word, make
some modifications and save it.

6.Change the name to sample.zip to verify the result. We can see the custom
file is not deleted by Word this time. But Word rename the folder to
customXML and the file to item1.xml.

You can get the detailed information about this in the following MSDN blog
article. What we are interested in is the "Adding a custom XML part to a
document" part:
http://blogs.msdn.com/dmahugh/archive/2007/05/19/custom-schemas-revisited.as
px.


Please let me know if this works for you or not. And if you have any future
concerns or questions. I am glad to be of future assistance.

Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

That works - but a couple of items:

1) It renames it items1.xml - how can I have it not rename it.

2) What if I want data other than an xml file (like a png file)?

thanks - dave


Hello Dave,

I am sorry about that I make a mistake in my last reply. Indeed, adding the
extension definition only makes Word do not consider the document as
corrupted. But, the custom file will still be removed from the Word
document.

To add a custom file into the zipped document anywhere, we need to define
the custom file's relationship in the file word\_rels\document.xml.rels. I
achieve that with the following steps:

1.Create a word 2007 file named sample.docx. Open it, type some text and
save it.

2.Change sample.docx name to sample.zip and extract the zip file to the
local driver.

3.Create the data folder and create the custom file order.xml in the new
created folder.

4.Open and edit the file word\_rels\document.xml.rels. Add the following
relationship before the </relationships> mark and save it.
<Relationship Id="myCustomXmlRelationship"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/cu
stomXml" Target="../data/order.xml" />

5.Zip and change the file name back to sample.docx. Open it in Word, make
some modifications and save it.

6.Change the name to sample.zip to verify the result. We can see the custom
file is not deleted by Word this time. But Word rename the folder to
customXML and the file to item1.xml.

You can get the detailed information about this in the following MSDN blog
article. What we are interested in is the "Adding a custom XML part to a
document" part:
http://blogs.msdn.com/dmahugh/archive/2007/05/19/custom-schemas-revisited.as
px.


Please let me know if this works for you or not. And if you have any future
concerns or questions. I am glad to be of future assistance.

Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Ji Zhou [MSFT]

Hello Dave,

After some more investigations, I achieve these two objectives by the
following steps:

1.Create the data folder, and put order.xml and test.png file in it.

2.Define the png file extension: (Add the following line in the
[Content_Types].xml file)
<Default Extension="png" ContentType="image/png"/>

3.Add two relationship definition in word/_rels/document.xml.rels as
follows:
<Relationship Id="myCustomXmlRelationship" Type="http://test.com"
Target="../data/Order.xml"/>
<Relationship Id="myCustomXmlRelationship2" Type="http://test.com"
Target="../data/test.png"/>


In fact, Word renames our custom file because we define the relationship
type as
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/cu
stomXml", this type is a recognizable type by Word. If Word encounters this
type relationship, it will rename the defined file. So, I changed the type
to "http://test.com" in order to avoid the renaming.

Please let me know if you have any future questions. Have a good day, Dave!

Best regards,
Ji Zhou ([email protected])
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

thank you

Hello Dave,

After some more investigations, I achieve these two objectives by the
following steps:

1.Create the data folder, and put order.xml and test.png file in it.

2.Define the png file extension: (Add the following line in the
[Content_Types].xml file)
<Default Extension="png" ContentType="image/png"/>

3.Add two relationship definition in word/_rels/document.xml.rels as
follows:
<Relationship Id="myCustomXmlRelationship" Type="http://test.com"
Target="../data/Order.xml"/>
<Relationship Id="myCustomXmlRelationship2" Type="http://test.com"
Target="../data/test.png"/>


In fact, Word renames our custom file because we define the relationship
type as
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/cu
stomXml", this type is a recognizable type by Word. If Word encounters this
type relationship, it will rename the defined file. So, I changed the type
to "http://test.com" in order to avoid the renaming.

Please let me know if you have any future questions. Have a good day, Dave!

Best regards,
Ji Zhou ([email protected])
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top