New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embedded documents with images breaks "Save As" on Word for Mac #645
Comments
@paulresdat, thank you very much for this excellent issue description, which is a perfect example of how one should do it. Based on your description, I reproduced the behavior. Microsoft Word for Mac shows the behavior you describe, and Microsoft Word for Windows works as expected. I even made some changes to your sample code to see whether that makes a difference because your sample code has a few issues:
Finally, I streamlined the code a little and cast it as a unit test. Here's the result: using System;
using System.IO;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Xunit;
namespace CodeSnippets.Tests.OpenXml.Wordprocessing
{
public class AltChunkImagesTests
{
private static AltChunk CreateAltChunkFromWordDocument(
string sourcePath,
WordprocessingDocument destWordDocument)
{
string altChunkId = "AltChunkId-" + Guid.NewGuid();
AlternativeFormatImportPart chunk = destWordDocument.MainDocumentPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML, altChunkId);
using FileStream fs = File.Open(sourcePath, FileMode.Open);
chunk.FeedData(fs);
return new AltChunk { Id = altChunkId };
}
[Fact]
public void CanAppendDocumentWithImage()
{
const string destinationDoc = "test-destination.docx";
const string sourceDoc = "Resources/test-source.docx";
const string appendedDoc = "Resources/test-append.docx";
File.Copy(sourceDoc, destinationDoc, true);
using WordprocessingDocument destWordDocument = WordprocessingDocument.Open(destinationDoc, true);
Body body = destWordDocument.MainDocumentPart.Document.Body;
Paragraph p2 = body.InsertAfter(
new Paragraph(
new ParagraphProperties(
new PageBreakBefore()),
new Run(
new RunProperties(new Bold()),
new TabChar(),
new Text(appendedDoc)),
new Run(
new Break()),
new Run(
new RunProperties(new Italic()),
new TabChar(),
new Text("Uploaded by:")),
new Run(
new RunProperties(new Italic()),
new TabChar(),
new Text("Test User"))),
body.Elements<Paragraph>().Last());
p2.InsertAfterSelf(
CreateAltChunkFromWordDocument(appendedDoc, destWordDocument));
}
}
} Unfortunately, as already mentioned above, Microsoft Word for Mac shows the same behavior even with my "improved" version, which works perfectly well with Microsoft Word for Windows. I've also uploaded So, what do we have now?
Thus, my strong hypothesis is that it is a bug (or limitation in conjunction with a usability issue) of Microsoft Word for Mac rather than an issue with the Open XML SDK. Would you be able to test this with another application that supports Open XML? Unfortunately, I don't have any other wordprocessing applications that I could use for testing. |
@ThomasBarnekow - thank you for taking the timeout to test this and for the kind words! 👍 I'm in the process of downloading Open Office so I will follow up with a verdict on a different applicaiton. However as far as our environment at work, we do not use Open Office. We're tied to Microsoft and so a work around to use another application won't suffice as a solution for us. However I've come up with a code work around that basically copies the internals of one document to another. To me this is hackish but could suffice for the interim. I have a question in the meantime: If this is a bug with Microsoft Word, how can this issue be escalated to the Word team so that it can be addressed for Word on Mac? |
Thanks @ThomasBarnekow for your investigation. As this is not an issue with the SDK, i'll close the issue. Please use stack overflow for any Q&A of how to use the SDK. Thanks! |
Is this a:
Description
Using OpenXML, appending a word document with embedded images into another word document using
AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId)
causes an issue where the user can not "Save" or "Save As" when altering the content in Word for Mac.Information
Repro
Observed
When I open the destination document using Word on Mac, I will indeed see the document contents embedded in the destination document, however I can no longer utilize "Save" or "Save As". Upon clicking "save" on a "Save As" when changing the name of the file, you will see the file name revert back to the original document name in the title and when you go to your "Save As" destination, you will not find a new document. This problem does not exist in Word for Windows.
Expected
The document should be able to be altered and saved within the MacOS Word application.
The text was updated successfully, but these errors were encountered: