I have to implement a Microsoft Word document generator with embed excel graphics in it. One of my constraint is to make my generated docx work both with Microsoft word 2010 and 2003 + compatibility pack.
I didn't managed to make it works for both of them. I can make it works for Word 2010 but the document are not working for 2003 and vice versa.
After several search to make it work for Word 2003 I have added this in my code :
private static void Word2003(ChartPart importedChartPart, MainDocumentPart mainDocumentPart, Stream fileStream)
{
var ext = new ExternalData { Id = "rel" + 5 };
importedChartPart.ChartSpace.InsertAt(ext, 3);
var fi = new FileInfo(@"generated.xlsx");
importedChartPart.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/package", new Uri(fi.Name, UriKind.Relative), "rel5");
EmbeddedPackagePart embeddedObjectPart = mainDocumentPart.AddEmbeddedPackagePart(@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Stream copyStream = new MemoryStream();
fileStream.CopyTo(copyStream);
embeddedObjectPart.FeedData(copyStream);
}
But at this point generated documents don't work with Word 2010. If I delete these two lignes :
var ext = new ExternalData { Id = "rel" + 5 };
importedChartPart.ChartSpace.InsertAt(ext, 3);
from previous code it's works for Word 2010 but not for Word 2003.
I have tried several things but I didn't manage to make it work for each case.
You can find this small piece of code here
The prerequisite is a template of Excel file with a Chart and a graphic in it.
Edit : Generated document always works with Microsoft Office 2007 (with the two problematic code lines or not). I'm still seeking for solutions !